Skip to content

Commit

Permalink
BackupService: don't try to delete remote backups if no remote backup…
Browse files Browse the repository at this point in the history
… has been setup
  • Loading branch information
srosset81 committed Dec 19, 2024
1 parent efe11fd commit 7864098
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
44 changes: 20 additions & 24 deletions src/middleware/packages/backup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,44 +123,40 @@ const BackupService = {
},
deleteDataset: {
params: {
dataset: { type: 'string' },
iKnowWhatImDoing: { type: 'boolean' }
dataset: { type: 'string' }
},
async handler(ctx) {
const { dataset, iKnowWhatImDoing } = ctx.params;
const { dataset } = ctx.params;
const {
copyMethod,
remoteServer,
localServer: { fusekiBase }
} = this.settings;
if (!iKnowWhatImDoing) {
throw new Error(
'Please confirm that you know what you are doing and set the `iKnowWhatImDoing` parameter to `true`.'
);
}

const deleteFilenames = await ctx.call('backup.listBackupsForDataset', { dataset });

// Delete all backups locally.
await Promise.all(deleteFilenames.map(file => fs.promises.rm(file)));

// Delete backups from remote.fusekiBase
switch (copyMethod) {
case 'rsync':
// The last param sets the --deletion argument, to sync deletions too.
await rsyncCopy(pathJoin(fusekiBase, 'backups'), 'datasets', remoteServer, true);
break;

case 'ftp':
await ftpRemove(deleteFilenames, remoteServer);
break;

case 'fs':
await fsRemove(deleteFilenames, 'datasets', remoteServer);
break;

default:
throw new Error(`Unknown copy method: ${copyMethod}`);
if (remoteServer.path) {
switch (copyMethod) {
case 'rsync':
// The last param sets the --deletion argument, to sync deletions too.
await rsyncCopy(pathJoin(fusekiBase, 'backups'), 'datasets', remoteServer, true);
break;

case 'ftp':
await ftpRemove(deleteFilenames, remoteServer);
break;

case 'fs':
await fsRemove(deleteFilenames, 'datasets', remoteServer);
break;

default:
throw new Error(`Unknown copy method: ${copyMethod}`);
}
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/packages/backup/utils/rsyncCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ const rsyncCopy = (path, subDir, remoteServer, syncDelete = false) => {
if (syncDelete) rsync.set('delete');

return new Promise((resolve, reject) => {
this.logger.info(`Rsync started with command: ${rsync.command()}`);
console.log(`Rsync started with command: ${rsync.command()}`);
rsync.execute(error => {
if (error) {
reject(error);
} else {
this.logger.info('Rsync finished !');
console.log('Rsync finished !');
resolve();
}
});
Expand Down

0 comments on commit 7864098

Please sign in to comment.