diff --git a/docs/references/selfhosting.md b/docs/references/selfhosting.md index 9efbc98b4..8477934ea 100644 --- a/docs/references/selfhosting.md +++ b/docs/references/selfhosting.md @@ -206,8 +206,8 @@ IP of the server created above. If your DNS provider has an API, please open an ## Backups The Cloudron creates encrypted backups once a day. Each app is backed up independently and these -backups have the prefix `appbackup_`. The platform state is backed up independently with the -prefix `backup_`. +backups have the prefix `app_`. The platform state is backed up independently with the +prefix `box_`. By default, backups reside in `/var/backups`. Please note that having backups reside in the same physical machine as the Cloudron server instance is dangerous and it must be changed to diff --git a/src/backups.js b/src/backups.js index 6946d1171..f6b48c297 100644 --- a/src/backups.js +++ b/src/backups.js @@ -132,7 +132,6 @@ function getByAppIdPaged(page, perPage, appId, callback) { }); } -// backupId is the filename. appbackup_%s_%s-v%s.tar.gz function getRestoreConfig(backupId, callback) { assert.strictEqual(typeof backupId, 'string'); assert.strictEqual(typeof callback, 'function'); @@ -149,7 +148,6 @@ function getRestoreConfig(backupId, callback) { }); } -// backupId is the filename. appbackup_%s_%s-v%s.tar.gz function getRestoreUrl(backupId, callback) { assert.strictEqual(typeof backupId, 'string'); assert.strictEqual(typeof callback, 'function'); @@ -180,9 +178,9 @@ function copyLastBackup(app, manifest, callback) { assert(manifest && typeof manifest === 'object'); assert.strictEqual(typeof callback, 'function'); - var now = new Date(); - var toFilenameArchive = util.format('appbackup_%s_%s-v%s.tar.gz', app.id, now.toISOString(), manifest.version); - var toFilenameConfig = util.format('appbackup_%s_%s-v%s.json', app.id, now.toISOString(), manifest.version); + var timestamp = (new Date()).toISOString().replace('T', '-').replace(/:|\..*/g,''); + var toFilenameArchive = util.format('app_%s_%s_v%s.tar.gz', app.id, timestamp, manifest.version); + var toFilenameConfig = util.format('app_%s_%s_v%s.json', app.id, timestamp, manifest.version); settings.getBackupConfig(function (error, backupConfig) { if (error) return callback(new BackupsError(BackupsError.INTERNAL_ERROR, error)); @@ -209,8 +207,8 @@ function copyLastBackup(app, manifest, callback) { function backupBoxWithAppBackupIds(appBackupIds, callback) { assert(util.isArray(appBackupIds)); - var now = new Date(); - var filebase = util.format('backup_%s-v%s', now.toISOString(), config.version()); + var timestamp = (new Date()).toISOString().replace('T', '-').replace(/:|\..*/g,''); + var filebase = util.format('box_%s_v%s', timestamp, config.version()); var filename = filebase + '.tar.gz'; settings.getBackupConfig(function (error, backupConfig) { @@ -269,8 +267,8 @@ function createNewAppBackup(app, manifest, callback) { assert(manifest && typeof manifest === 'object'); assert.strictEqual(typeof callback, 'function'); - var now = new Date(); - var filebase = util.format('appbackup_%s_%s-v%s', app.id, now.toISOString(), manifest.version); + var timestamp = (new Date()).toISOString().replace('T', '-').replace(/:|\..*/g,''); + var filebase = util.format('app_%s_%s_v%s', app.id, timestamp, manifest.version); var configFilename = filebase + '.json', dataFilename = filebase + '.tar.gz'; settings.getBackupConfig(function (error, backupConfig) { diff --git a/src/scripts/backupapp.sh b/src/scripts/backupapp.sh index d4a58ff25..9ca06fc75 100755 --- a/src/scripts/backupapp.sh +++ b/src/scripts/backupapp.sh @@ -50,7 +50,7 @@ elif [[ "$1" == "filesystem" ]]; then fi # perform backup -readonly now=$(date "+%Y-%m-%dT%H:%M:%S") +readonly now=$(date "+%Y-%m-%d-%H%M%S") readonly app_data_dir="${DATA_DIR}/${app_id}" readonly app_data_snapshot="${DATA_DIR}/snapshots/${app_id}-${now}" diff --git a/src/scripts/backupbox.sh b/src/scripts/backupbox.sh index 9a8c8fdfe..6216d68ce 100755 --- a/src/scripts/backupbox.sh +++ b/src/scripts/backupbox.sh @@ -46,7 +46,7 @@ if [[ "$1" == "filesystem" ]]; then fi # perform backup -now=$(date "+%Y-%m-%dT%H:%M:%S") +now=$(date "+%Y-%m-%d-%H%M%S") BOX_DATA_DIR="${HOME}/data/box" box_snapshot_dir="${HOME}/data/snapshots/box-${now}" diff --git a/src/test/database-test.js b/src/test/database-test.js index 05c69f04b..17bb9970a 100644 --- a/src/test/database-test.js +++ b/src/test/database-test.js @@ -1065,7 +1065,7 @@ describe('database', function () { it('add app succeeds', function (done) { var backup = { - id: 'appbackup_appid_123', + id: 'app_appid_123', version: '1.0.0', type: backupdb.BACKUP_TYPE_APP, dependsOn: [ ] @@ -1078,7 +1078,7 @@ describe('database', function () { }); it('get succeeds', function (done) { - backupdb.get('appbackup_appid_123', function (error, result) { + backupdb.get('app_appid_123', function (error, result) { expect(error).to.be(null); expect(result.version).to.be('1.0.0'); expect(result.type).to.be(backupdb.BACKUP_TYPE_APP); @@ -1094,7 +1094,7 @@ describe('database', function () { expect(results).to.be.an(Array); expect(results.length).to.be(1); - expect(results[0].id).to.be('appbackup_appid_123'); + expect(results[0].id).to.be('app_appid_123'); expect(results[0].version).to.be('1.0.0'); expect(results[0].dependsOn).to.eql([]); @@ -1103,11 +1103,11 @@ describe('database', function () { }); it('delete succeeds', function (done) { - backupdb.del('appbackup_appid_123', function (error, result) { + backupdb.del('app_appid_123', function (error, result) { expect(error).to.be(null); expect(result).to.not.be.ok(); - backupdb.get('appbackup_appid_123', function (error, result) { + backupdb.get('app_appid_123', function (error, result) { expect(error).to.be.a(DatabaseError); expect(error.reason).to.equal(DatabaseError.NOT_FOUND); expect(result).to.not.be.ok();