Skip to content

Commit

Permalink
Merge pull request #63 from simatec/multiplatform
Browse files Browse the repository at this point in the history
(simatec) Fix nfs/cifs mount and umount
  • Loading branch information
simatec authored Dec 3, 2018
2 parents 1561c1f + 4644799 commit 4ebe736
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 52 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Backitup is a backup solution that allows cyclical backup of an IoBroker install

## Changelog

### 0.3.9 (03.12.2018)
* (simatec) Fix cifs/nfs mount and umount

### 0.3.8 (08.11.2018)
* (simatec) Fix notifications format
* (simatec) Fix Telegram User
Expand Down
13 changes: 12 additions & 1 deletion io-package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
{
"common": {
"name": "backitup",
"version": "0.3.8",
"version": "0.3.9",
"news": {
"0.3.9": {
"en": "Fix cifs/nfs mount and umount",
"de": "Fix cifs/nfs mount und umount",
"ru": "Исправить cifs/nfs mount и umount",
"pt": "Fixar cifs/nfs mount e umount",
"nl": "Fix cifs/nfs mount en umount",
"fr": "Correction du montage et du démontage de cifs/nfs",
"it": "Fix cifs / nfs mount e umount",
"es": "Corregir cifs/nfs mount y umount",
"pl": "Napraw mocowanie cifs/nfs i umount"
},
"0.3.8": {
"en": "Fix Telegram User, Fix notifications format",
"de": "Fix Telegrambenutzer, Fix Benachrichtigungsformat",
Expand Down
25 changes: 14 additions & 11 deletions lib/list/cifs.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ function mount(options, log, callback) {
if (error) {
callback(error);
} else {
fs.writeFileSync(__dirname + '/.mount', options.mountType);
fs.writeFileSync(options.fileDir + '/.mount', options.mountType);
callback(null, stdout);
}
});
} else {
fs.writeFileSync(__dirname + '/.mount', options.mountType);
fs.writeFileSync(options.fileDir + '/.mount', options.mountType);
callback(null, stdout);
}
});
Expand All @@ -155,7 +155,7 @@ function mount(options, log, callback) {
if (error) {
callback(error);
} else {
fs.writeFileSync(__dirname + '/.mount', options.mountType);
fs.writeFileSync(options.fileDir + '/.mount', options.mountType);
callback(null, stdout);
}
});
Expand All @@ -166,14 +166,17 @@ function umount(options, log, callback) {
if (!options.mount) {
return callback('NO mount path specified!');
}
child_process.exec(`umount ${backupDir}`, (error, stdout, stderr) => {
if (error) {
log.error(stderr);
callback(error)
} else {
callback(null, stdout);
}
});
if (fs.existsSync(options.fileDir + '/.mount')) {
child_process.exec(`umount ${backupDir}`, (error, stdout, stderr) => {
if (error) {
log.error(stderr);
callback(error)
} else {
fs.unlink(options.fileDir + '/.mount');
callback(null, stdout);
}
});
}
}

module.exports = {
Expand Down
73 changes: 48 additions & 25 deletions lib/scripts/01-mount.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const child_process = require('child_process');
const fs = require('fs');

function command(options, log, callback) {
if (options.mountType === 'CIFS' && options.mount && !options.mount.startsWith('//')) {
Expand All @@ -12,34 +13,56 @@ function command(options, log, callback) {
if (!options.mount) {
return callback('NO mount path specified!');
}
if (options.mountType === 'CIFS' || options.mountType === 'NFS') {
if (fs.existsSync(options.fileDir + '/.mount')) {
child_process.exec(`umount ${options.backupDir}`, (error, stdout, stderr) => {
if (error) {
options.context.errors.umount = error;
log.error(stderr);
callback(error)
} else {
options.context.done.push('umount');
fs.unlink(options.fileDir + '/.mount');
callback(null, stdout);
}
});
}
}
if (options.mountType === 'CIFS') {
child_process.exec(`mount -t cifs -o ${options.user ? 'user=' + options.user + ',password=' + options.pass : ''},rw,file_mode=0777,dir_mode=0777,vers=1.0 ${options.mount}${options.dir} ${options.backupDir}`, (error, stdout, stderr) => {
if (error) {
child_process.exec(`mount -t cifs -o ${options.user ? 'user=' + options.user + ',password=' + options.pass : ''},rw,file_mode=0777,dir_mode=0777 ${options.mount}${options.dir} ${options.backupDir}`, (error, stdout, stderr) => {
if (error) {
log.error(`[${options.name} ${stderr}`);
callback(error);
} else {
options.context.done.push('mount');
callback(null, stdout);
}
});
} else {
options.context.done.push('mount');
callback(null, stdout);
}
});
setTimeout(function() {
child_process.exec(`mount -t cifs -o ${options.user ? 'user=' + options.user + ',password=' + options.pass : ''},rw,file_mode=0777,dir_mode=0777,vers=1.0 ${options.mount}${options.dir} ${options.backupDir}`, (error, stdout, stderr) => {
if (error) {
child_process.exec(`mount -t cifs -o ${options.user ? 'user=' + options.user + ',password=' + options.pass : ''},rw,file_mode=0777,dir_mode=0777 ${options.mount}${options.dir} ${options.backupDir}`, (error, stdout, stderr) => {
if (error) {
log.error(`[${options.name} ${stderr}`);
callback(error);
} else {
options.context.done.push('mount');
fs.writeFileSync(options.fileDir + '/.mount', options.mountType);
callback(null, stdout);
}
});
} else {
options.context.done.push('mount');
fs.writeFileSync(options.fileDir + '/.mount', options.mountType);
callback(null, stdout);
}
});
}, 3000);
}
if (options.mountType === 'NFS') {
child_process.exec(`mount ${options.mount}:${options.dir} ${options.backupDir}`, (error, stdout, stderr) => {
if (error) {
log.error(`[${options.name} ${stderr}`);
callback(error);
} else {
options.context.done.push('mount');
callback(null, stdout);
}
});
setTimeout(function() {
child_process.exec(`mount ${options.mount}:${options.dir} ${options.backupDir}`, (error, stdout, stderr) => {
if (error) {
log.error(`[${options.name} ${stderr}`);
callback(error);
} else {
options.context.done.push('mount');
fs.writeFileSync(options.fileDir + '/.mount', options.mountType);
callback(null, stdout);
}
});
}, 3000);
}
if (options.mountType === 'Copy') {
callback(null);
Expand Down
28 changes: 16 additions & 12 deletions lib/scripts/98-umount.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
'use strict';
const child_process = require('child_process');
const fs = require('fs');

function command(options, log, callback) {
if (!options.mount) {
return callback('NO mount path specified!');
}
if (options.mountType === 'CIFS' || options.mountType === 'NFS') {
setTimeout(function() {
child_process.exec(`umount ${options.backupDir}`, (error, stdout, stderr) => {
if (error) {
options.context.errors.umount = error;
log.error(stderr);
callback(error)
} else {
options.context.done.push('umount');
callback(null, stdout);
}
});
}, 10000);
if (fs.existsSync(options.fileDir + '/.mount')) {
setTimeout(function() {
child_process.exec(`umount ${options.backupDir}`, (error, stdout, stderr) => {
if (error) {
options.context.errors.umount = error;
log.error(stderr);
callback(error)
} else {
options.context.done.push('umount');
fs.unlink(options.fileDir + '/.mount');
callback(null, stdout);
}
});
}, 60000);
}
} else {
callback(null);
}
Expand Down
6 changes: 4 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ function initConfig(secret) {
type: 'storage',
source: adapter.config.restoreSource,
mount: adapter.config.cifsMount,
fileDir: __dirname,
//fileDir: = path.join(tools.getIobDir(), 'node_modules/iobroker.backitup'),
deleteOldBackup: adapter.config.cifsDeleteOldBackup, //Delete old Backups from Network Disk
ownDir: adapter.config.cifsOwnDir,
bkpType: adapter.config.restoreType,
Expand Down Expand Up @@ -478,13 +480,13 @@ function createBashScripts() {
}
// umount after restore
function umount() {
if (fs.existsSync(__dirname + '/lib/list/.mount')) {
if (fs.existsSync(__dirname + '/.mount')) {
const {spawn} = require('child_process');
const backupDir = path.join(tools.getIobDir(), 'backups');
const cmd = spawn('umount', [backupDir], {detached: true, cwd: __dirname, stdio: ['ignore', 'ignore', 'ignore']});

cmd.unref();
fs.unlink(__dirname + '/lib/list/.mount');
fs.unlink(__dirname + '/.mount');
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker.backitup",
"version": "0.3.8",
"version": "0.3.9",
"engines": {
"node": ">=6.0.0"
},
Expand Down

0 comments on commit 4ebe736

Please sign in to comment.