backups: root ~~canal~~ path surgery

remove rootPath and getBackupFilePath from the backup target and
make this backend specific.
This commit is contained in:
Girish Ramakrishnan
2025-08-02 01:46:29 +02:00
parent a01e1bad0f
commit c935744f4c
15 changed files with 378 additions and 373 deletions

View File

@@ -72,20 +72,20 @@ async function processSyncerChange(change, backupTarget, remotePath, dataLayout,
debug('sync: processing task: %j', change);
// the empty task.path is special to signify the directory
const destPath = change.path && backupTarget.encryption?.encryptedFilenames ? hush.encryptFilePath(change.path, backupTarget.encryption) : change.path;
const backupFilePath = path.join(backupTargets.getBackupFilePath(backupTarget, remotePath), destPath);
const fullPath = path.join(remotePath, destPath);
if (change.operation === 'removedir') {
debug(`Removing directory ${backupFilePath}`);
await backupTargets.storageApi(backupTarget).removeDir(backupTarget.config, backupFilePath, progressCallback);
debug(`Removing directory ${fullPath}`);
await backupTargets.storageApi(backupTarget).removeDir(backupTarget.config, fullPath, progressCallback);
} else if (change.operation === 'remove') {
debug(`Removing ${backupFilePath}`);
await backupTargets.storageApi(backupTarget).remove(backupTarget.config, backupFilePath);
debug(`Removing ${fullPath}`);
await backupTargets.storageApi(backupTarget).remove(backupTarget.config, fullPath);
} else if (change.operation === 'add') {
await promiseRetry({ times: 5, interval: 20000, debug }, async (retryCount) => {
progressCallback({ message: `Adding ${change.path}` + (retryCount > 1 ? ` (Try ${retryCount})` : '') });
debug(`Adding ${change.path} position ${change.position} try ${retryCount}`);
const uploader = await backupTargets.storageApi(backupTarget).upload(backupTarget.config, backupFilePath);
const uploader = await backupTargets.storageApi(backupTarget).upload(backupTarget.config, fullPath);
await addFile(dataLayout.toLocalPath('./' + change.path), backupTarget.encryption, uploader, progressCallback);
});
}
@@ -258,11 +258,9 @@ async function download(backupTarget, remotePath, dataLayout, progressCallback)
assert(dataLayout instanceof DataLayout, 'dataLayout must be a DataLayout');
assert.strictEqual(typeof progressCallback, 'function');
const backupFilePath = backupTargets.getBackupFilePath(backupTarget, remotePath);
debug(`download: Downloading ${remotePath} to ${dataLayout.toString()}`);
debug(`download: Downloading ${backupFilePath} to ${dataLayout.toString()}`);
await downloadDir(backupTarget, backupFilePath, dataLayout, progressCallback);
await downloadDir(backupTarget, remotePath, dataLayout, progressCallback);
await restoreFsMetadata(dataLayout, `${dataLayout.localRoot()}/fsmetadata.json`);
}
@@ -279,5 +277,5 @@ async function upload(backupTarget, remotePath, dataLayout, progressCallback) {
function getFileExtension(encryption) {
assert.strictEqual(typeof encryption, 'boolean');
return '';
return ''; // this also signals to backupcleanear that we are dealing with directories
}