diff --git a/setup/start.sh b/setup/start.sh index 9abeb25a4..1d96ecd73 100755 --- a/setup/start.sh +++ b/setup/start.sh @@ -203,20 +203,31 @@ mysql -u root -p${mysql_root_password} -e 'CREATE DATABASE IF NOT EXISTS box' if [[ -n "${arg_restore_url}" ]]; then set_progress "30" "Downloading restore data" - decrypt="" - if [[ "${arg_restore_url}" == *.tar.gz.enc || -n "${arg_restore_key}" ]]; then - echo "==> Downloading encrypted backup: ${arg_restore_url} and key: ${arg_restore_key}" - decrypt=(openssl aes-256-cbc -d -nosalt -pass "pass:${arg_restore_key}") - else - echo "==> Downloading backup: ${arg_restore_url}" - decrypt=(cat -) - fi + readonly restore_dir="${arg_restore_url#file://}" - while true; do - if $curl -L "${arg_restore_url}" | "${decrypt[@]}" \ - | tar -zxf - --overwrite -C "${BOX_DATA_DIR}"; then break; fi - echo "Failed to download data, trying again" - done + if [[ -d "${restore_dir}" ]]; then # rsync backup + echo "==> Copying backup: ${restore_dir}" + if [[ $(stat -c "%d" "${BOX_DATA_DIR}") == $(stat -c "%d" "${restore_dir}") ]]; then + cp -rl "${restore_dir}/." "${BOX_DATA_DIR}" + else + cp -r "${restore_dir}/." "${BOX_DATA_DIR}" + fi + else # tgz backup + decrypt="" + if [[ "${arg_restore_url}" == *.tar.gz.enc || -n "${arg_restore_key}" ]]; then + echo "==> Downloading encrypted backup: ${arg_restore_url} and key: ${arg_restore_key}" + decrypt=(openssl aes-256-cbc -d -nosalt -pass "pass:${arg_restore_key}") + elif [[ "${arg_restore_url}" == *.tar.gz ]]; then + echo "==> Downloading backup: ${arg_restore_url}" + decrypt=(cat -) + fi + + while true; do + if $curl -L "${arg_restore_url}" | "${decrypt[@]}" \ + | tar -zxf - --overwrite -C "${BOX_DATA_DIR}"; then break; fi + echo "Failed to download data, trying again" + done + fi set_progress "35" "Setting up MySQL" if [[ -f "${BOX_DATA_DIR}/box.mysqldump" ]]; then diff --git a/src/backups.js b/src/backups.js index 47ee661d7..f9bd53a03 100644 --- a/src/backups.js +++ b/src/backups.js @@ -520,16 +520,12 @@ function uploadBoxSnapshot(backupConfig, callback) { snapshotBox(function (error) { if (error) return callback(error); - // for the moment, box backups are always tarball based. this is because it makes it easy to restore - // in the future, if required, we can move out the mailboxes to a separate virtual app backup - const format = backupConfig.provider === 'exoscale-sos' ? 'rsync' : 'tgz'; // see also rotateBoxBackup - - runBackupTask('snapshot/box', format, paths.BOX_DATA_DIR, function (error) { + runBackupTask('snapshot/box', backupConfig.format, paths.BOX_DATA_DIR, function (error) { if (error) return callback(error); debug('uploadBoxSnapshot: time: %s secs', (new Date() - startTime)/1000); - setSnapshotInfo('box', { timestamp: new Date().toISOString(), format: format }, callback); + setSnapshotInfo('box', { timestamp: new Date().toISOString(), format: backupConfig.format }, callback); }); }); } @@ -545,7 +541,7 @@ function rotateBoxBackup(backupConfig, timestamp, appBackupIds, callback) { var snapshotTime = snapshotInfo.timestamp.replace(/[T.]/g, '-').replace(/[:Z]/g,''); var backupId = util.format('%s/box_%s_v%s', timestamp, snapshotTime, config.version()); - const format = backupConfig.provider === 'exoscale-sos' ? 'rsync' : 'tgz'; // // see also uploadBoxSnapshot + const format = backupConfig.format; log(`Rotating box backup to id ${backupId}`);