backups: encode extension into the remotePath
This commit is contained in:
@@ -16,22 +16,28 @@ exports.up = async function(db) {
|
||||
console.log(`Backup counts. rsync: ${rsyncCount} tgz: ${tgzCount} total: ${totalCount} . theOneFormat: ${theOneFormat}`);
|
||||
|
||||
results = await db.runSql('SELECT * FROM backupTargets');
|
||||
const current = results[0];
|
||||
let clone = null;
|
||||
if (current.format !== theOneFormat) {
|
||||
clone = Object.assign({}, results[0], { id: `bc-${crypto.randomUUID()}` });
|
||||
clone.format = current.format === 'rsync' ? 'tgz' : 'rsync';
|
||||
clone.priority = false;
|
||||
clone.schedule = 'never';
|
||||
console.log(`Existing format is ${current.format} . Adding clone backup target for ${clone.format}`);
|
||||
const currentBackupTarget = results[0];
|
||||
let cloneBackupTarget = null;
|
||||
if (currentBackupTarget.format !== theOneFormat) {
|
||||
cloneBackupTarget = Object.assign({}, results[0], { id: `bc-${crypto.randomUUID()}` });
|
||||
cloneBackupTarget.format = currentBackupTarget.format === 'rsync' ? 'tgz' : 'rsync';
|
||||
cloneBackupTarget.priority = false;
|
||||
cloneBackupTarget.schedule = 'never';
|
||||
console.log(`Existing format is ${currentBackupTarget.format} . Adding clone backup target for ${cloneBackupTarget.format}`);
|
||||
|
||||
await db.runSql('INSERT INTO backupTargets (id, label, configJson, limitsJson, retentionJson, schedule, encryptionJson, format, priority) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
[ clone.id, clone.label, clone.configJson, clone.limitsJson, clone.retentionJson, clone.schedule, clone.encryptionJson, clone.format, clone.priority ]);
|
||||
[ cloneBackupTarget.id, cloneBackupTarget.label, cloneBackupTarget.configJson, cloneBackupTarget.limitsJson, cloneBackupTarget.retentionJson, cloneBackupTarget.schedule,
|
||||
cloneBackupTarget.encryptionJson, cloneBackupTarget.format, cloneBackupTarget.priority ]);
|
||||
}
|
||||
|
||||
await db.runSql('ALTER TABLE backups ADD targetId VARCHAR(128)');
|
||||
await db.runSql('UPDATE backups SET targetId=? WHERE format=?', [ current.id, current.format ]);
|
||||
if (clone) await db.runSql('UPDATE backups SET targetId=? WHERE format=?', [ clone.id, clone.format ]);
|
||||
if (currentBackupTarget.format === 'tgz') {
|
||||
const ext = currentBackupTarget.encryptionJson ? '.tar.gz.enc' : '.tar.gz';
|
||||
console.log(`Adjusting remotePath of existing tgz backups with ${ext}`);
|
||||
await db.runSql('UPDATE backups SET remotePath=CONCAT(remotePath, ?) WHERE format=?', [ ext, 'tgz' ]);
|
||||
}
|
||||
await db.runSql('UPDATE backups SET targetId=? WHERE format=?', [ currentBackupTarget.id, currentBackupTarget.format ]);
|
||||
if (cloneBackupTarget) await db.runSql('UPDATE backups SET targetId=? WHERE format=?', [ cloneBackupTarget.id, cloneBackupTarget.format ]);
|
||||
await db.runSql('ALTER TABLE backups MODIFY targetId VARCHAR(128) NOT NULL');
|
||||
await db.runSql('ALTER TABLE backups ADD FOREIGN KEY(targetId) REFERENCES backupTargets(id)');
|
||||
await db.runSql('ALTER TABLE backups DROP COLUMN format');
|
||||
|
||||
@@ -20,13 +20,10 @@ function getBackupFilePath(backupTarget, remotePath) {
|
||||
assert.strictEqual(typeof backupTarget, 'object');
|
||||
assert.strictEqual(typeof remotePath, 'string');
|
||||
|
||||
const rootPath = backupTarget.config.rootPath;
|
||||
const fileType = backupTarget.encryption ? '.tar.gz.enc' : '.tar.gz';
|
||||
|
||||
// we don't have a rootPath for noop
|
||||
if (backupTarget.provider === 'noop') return remotePath + fileType;
|
||||
if (backupTarget.provider === 'noop') return remotePath;
|
||||
|
||||
return path.join(rootPath, remotePath + fileType);
|
||||
return path.join(backupTarget.config.rootPath, remotePath);
|
||||
}
|
||||
|
||||
// In tar, the entry header contains the file size. If we don't provide it those many bytes, the tar will become corrupt
|
||||
|
||||
Reference in New Issue
Block a user