backups (tgz): work with a layout

this will allow us to place the localstorage directory in an arbitrary
location
This commit is contained in:
Girish Ramakrishnan
2018-12-20 14:33:29 -08:00
parent 3500236d32
commit 13c628b58b
15 changed files with 219 additions and 42 deletions

View File

@@ -21,11 +21,11 @@ function initialize(callback) {
}
// Main process starts here
var backupId = process.argv[2];
var format = process.argv[3];
var dataDir = process.argv[4];
const backupId = process.argv[2];
const format = process.argv[3];
const dataLayout = JSON.parse(process.argv[4]);
debug(`Backing up ${dataDir} to ${backupId}`);
debug(`Backing up ${JSON.stringify(dataLayout)} to ${backupId}`);
process.on('SIGTERM', function () {
process.exit(0);
@@ -40,7 +40,7 @@ process.on('disconnect', function () {
initialize(function (error) {
if (error) throw error;
backups.upload(backupId, format, dataDir, (progress) => process.send(progress), function resultHandler(error) {
backups.upload(backupId, format, dataLayout, (progress) => process.send(progress), function resultHandler(error) {
if (error) debug('upload completed with error', error);
debug('upload completed');

23
src/scripts/mkdirvolume.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
set -eu -o pipefail
if [[ ${EUID} -ne 0 ]]; then
echo "This script should be run as root." > /dev/stderr
exit 1
fi
if [[ $# -eq 0 ]]; then
echo "No arguments supplied"
exit 1
fi
if [[ "$1" == "--check" ]]; then
echo "OK"
exit 0
fi
volume_dir="$1"
mkdir -p "${volume_dir}"

35
src/scripts/mvvolume.sh Executable file
View File

@@ -0,0 +1,35 @@
#!/bin/bash
set -eu -o pipefail
if [[ ${EUID} -ne 0 ]]; then
echo "This script should be run as root." > /dev/stderr
exit 1
fi
if [[ $# -eq 0 ]]; then
echo "No arguments supplied"
exit 1
fi
if [[ "$1" == "--check" ]]; then
echo "OK"
exit 0
fi
source_dir="$1"
target_dir="$2"
if [[ "${BOX_ENV}" == "test" ]]; then
# be careful not to nuke some random directory when testing
[[ "${source_dir}" != *"./cloudron_test/"* ]] && exit 1
[[ "${target_dir}" != *"./cloudron_test/"* ]] && exit 1
fi
# copy and remove - this way if the copy fails, the original is intact
# the find logic is so that move to a subdir works (and we also move hidden files)
find "${source_dir}" -maxdepth 1 -mindepth 1 -not -wholename "${target_dir}" -exec cp -ar '{}' "${target_dir}" \;
find "${source_dir}" -maxdepth 1 -mindepth 1 -not -wholename "${target_dir}" -exec rm -rf '{}' \;
# this will fail if target is a subdir
rmdir "${source_dir}" || true