.
This commit is contained in:
parent
63490d9ce3
commit
1776a7e45f
@ -491,6 +491,12 @@ bool service_runner::restore(std::string backup_file, bool silent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string local_backups_dir = gConfig().get_local_backup_path();
|
std::string local_backups_dir = gConfig().get_local_backup_path();
|
||||||
|
|
||||||
|
if (backup_file == "latest") {
|
||||||
|
// get the latest backup file from the server
|
||||||
|
backup_file = get_latest_backup_file(mServer, mService);
|
||||||
|
}
|
||||||
|
|
||||||
std::string local_backup_file_path = (std::filesystem::path(local_backups_dir) / backup_file).string();
|
std::string local_backup_file_path = (std::filesystem::path(local_backups_dir) / backup_file).string();
|
||||||
|
|
||||||
if (! std::filesystem::exists(local_backup_file_path)) {
|
if (! std::filesystem::exists(local_backup_file_path)) {
|
||||||
@ -520,14 +526,6 @@ bool service_runner::restore(std::string backup_file, bool silent)
|
|||||||
std::cout << "Restoring " << nicedate << " backup of " << backup_template_name << " taken from "<<backup_server_name<<", onto "<<mServer<<"/"<<mService<<std::endl;
|
std::cout << "Restoring " << nicedate << " backup of " << backup_template_name << " taken from "<<backup_server_name<<", onto "<<mServer<<"/"<<mService<<std::endl;
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
std::cout << "*** ALL DATA FOR "<<mServer<<"/"<<mService<<" WILL BE OVERWRITTEN! ***"<<std::endl;
|
std::cout << "*** ALL DATA FOR "<<mServer<<"/"<<mService<<" WILL BE OVERWRITTEN! ***"<<std::endl;
|
||||||
std::cout << std::endl;
|
|
||||||
std::cout << "Are you sure you want to continue? (y/n)" << std::endl;
|
|
||||||
char confirm;
|
|
||||||
std::cin >> confirm;
|
|
||||||
if (confirm != 'y') {
|
|
||||||
std::cout << "Restore cancelled." << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// run the restore script
|
// run the restore script
|
||||||
std::cout << "OK, here goes..." << std::endl;
|
std::cout << "OK, here goes..." << std::endl;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
MYID=$(id -u)
|
||||||
|
MYGRP=$(id -g)
|
||||||
|
|
||||||
_autocommandrun_volume() {
|
_autocommandrun_volume() {
|
||||||
command="$1"
|
command="$1"
|
||||||
@ -15,16 +17,16 @@ _autocommandrun_volume() {
|
|||||||
docker volume rm ${volume_name}
|
docker volume rm ${volume_name}
|
||||||
;;
|
;;
|
||||||
backup)
|
backup)
|
||||||
local backup_file="$3"
|
local backup_folder="$3"
|
||||||
echo "Backing up volume ${volume_name}"
|
echo "Backing up volume ${volume_name}"
|
||||||
docker run --rm -v ${volume_name}:/volume -v ${temp_path}:/backup alpine tar -czvf /backup/volume.tar.gz -C /volume .
|
docker run --rm -v ${volume_name}:/volume -v ${backup_folder}:/backup debian bash -c "tar -czvf /backup/backup.tgz -C /volume . && chown -R $MYID:$MYGRP /backup"
|
||||||
;;
|
;;
|
||||||
restore)
|
restore)
|
||||||
local backup_file="$3"
|
local backup_folder="$3"
|
||||||
echo "Restoring volume ${volume_name}"
|
echo "Restoring volume ${volume_name}"
|
||||||
docker volume rm ${volume_name}
|
docker volume rm ${volume_name}
|
||||||
docker volume create ${volume_name}
|
docker volume create ${volume_name}
|
||||||
docker run --rm -v ${volume_name}:/volume -v ${temp_path}:/backup alpine tar -xzvf /backup/volume.tar.gz -C /volume --strip-components=1
|
docker run --rm -v ${volume_name}:/volume -v ${backup_folder}:/backup debian bash -c "tar -xzvf /backup/backup.tgz -C /volume --strip-components=1"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@ -43,14 +45,14 @@ _autocommandrun_path() {
|
|||||||
rm -rf ${path}
|
rm -rf ${path}
|
||||||
;;
|
;;
|
||||||
backup)
|
backup)
|
||||||
local backup_file="$3"
|
local backup_folder="$3"
|
||||||
echo "Backing up path ${path}"
|
echo "Backing up path ${path}"
|
||||||
tar -czvf ${backup_file} -C ${path} .
|
tar -czvf ${backup_folder}/backup.tgz -C ${path} .
|
||||||
;;
|
;;
|
||||||
restore)
|
restore)
|
||||||
local backup_file="$3"
|
local backup_folder="$3"
|
||||||
echo "Restoring path ${path}"
|
echo "Restoring path ${path}"
|
||||||
tar -xzvf ${backup_file} -C ${path} --strip-components=1
|
tar -xzvf ${backup_folder}/backup.tgz -C ${path} --strip-components=1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@ -66,14 +68,17 @@ _autocommandrun_file() {
|
|||||||
rm -f ${value}
|
rm -f ${value}
|
||||||
;;
|
;;
|
||||||
backup)
|
backup)
|
||||||
local backup_file="$3"
|
local backup_folder="$3"
|
||||||
echo "Backing up file ${value}"
|
echo "Backing up file ${value}"
|
||||||
cp ${value} ${backup_file}
|
# get filename from path
|
||||||
|
local filename=$(basename ${value})
|
||||||
|
cp ${value} ${backup_folder}/${filename}
|
||||||
;;
|
;;
|
||||||
restore)
|
restore)
|
||||||
local backup_file="$3"
|
local backup_folder="$3"
|
||||||
echo "Restoring file ${value}"
|
echo "Restoring file ${value}"
|
||||||
cp ${backup_file} ${value}
|
local filename=$(basename ${value})
|
||||||
|
cp ${backup_folder}/${filename} ${value}
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@ -92,9 +97,11 @@ _autocommandparse() {
|
|||||||
local command="$1"
|
local command="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
local temp_path="$2"
|
local temp_path="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
|
echo "autocommandparse: command=$command temp_path=$temp_path"
|
||||||
|
|
||||||
# Extract the backup file and temp path (last two arguments)
|
# Extract the backup file and temp path (last two arguments)
|
||||||
local args=("$@")
|
local args=("$@")
|
||||||
local arg_count=${#args[@]}
|
local arg_count=${#args[@]}
|
||||||
@ -111,18 +118,27 @@ _autocommandparse() {
|
|||||||
local key="${pair%%=*}"
|
local key="${pair%%=*}"
|
||||||
local value="${pair#*=}"
|
local value="${pair#*=}"
|
||||||
|
|
||||||
local bfile="${temp_path}/${key}_${value}.tgz"
|
# create backup folder unique to key/value.
|
||||||
|
local bfolder="${key}_${value}"
|
||||||
|
|
||||||
|
# remove any non-alphanumeric characters, that aren't dash or underscore from the bfile
|
||||||
|
targetpath=""
|
||||||
|
if [ ! "$temp_path" == "-" ]; then
|
||||||
|
bfolder=$(echo "$bfolder" | tr -cd '[:alnum:]_-')
|
||||||
|
mkdir -p ${temp_path}/${bfolder}
|
||||||
|
targetpath="${temp_path}/${bfolder}"
|
||||||
|
fi
|
||||||
|
|
||||||
# Key must be one of volume, path or file
|
# Key must be one of volume, path or file
|
||||||
case "$key" in
|
case "$key" in
|
||||||
volume)
|
volume)
|
||||||
_autocommandrun_volume "$command" "$value" "$bfile"
|
_autocommandrun_volume "$command" "$value" "$targetpath"
|
||||||
;;
|
;;
|
||||||
path)
|
path)
|
||||||
_autocommandrun_path "$command" "$value" "$bfile"
|
_autocommandrun_path "$command" "$value" "$targetpath"
|
||||||
;;
|
;;
|
||||||
file)
|
file)
|
||||||
_autocommandrun_file "$command" "$value" "$bfile"
|
_autocommandrun_file "$command" "$value" "$targetpath"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
_die "Unknown key $key passed to auto${command}. We only support volume, path and file."
|
_die "Unknown key $key passed to auto${command}. We only support volume, path and file."
|
||||||
@ -148,12 +164,13 @@ autobackup() {
|
|||||||
local temp_path="$1"
|
local temp_path="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
[ -f "$backup_file" ] || _die "Backup file $backup_file does not exist"
|
[ -f "$backup_file" ] && _die "Backup file $backup_file already exists"
|
||||||
[ -d "$temp_path" ] || _die "Temp path $temp_path does not exist"
|
[ -d "$temp_path" ] || _die "Temp path $temp_path does not exist"
|
||||||
|
|
||||||
local backup_temp_path="$temp_path/backup"
|
local backup_temp_path="$temp_path/backup"
|
||||||
|
|
||||||
mkdir -p "$backup_temp_path"
|
mkdir -p "$backup_temp_path"
|
||||||
|
echo "_autocommandparse [backup] [$backup_temp_path] [$@]"
|
||||||
_autocommandparse backup "$backup_temp_path" "$@"
|
_autocommandparse backup "$backup_temp_path" "$@"
|
||||||
|
|
||||||
tar zcvf "$backup_file" -C "$backup_temp_path" .
|
tar zcvf "$backup_file" -C "$backup_temp_path" .
|
||||||
|
@ -48,7 +48,7 @@ title "Backing up service"
|
|||||||
ds backup localhost $SERVICE_NAME || die "Failed to backup service"
|
ds backup localhost $SERVICE_NAME || die "Failed to backup service"
|
||||||
|
|
||||||
title "Restoring service"
|
title "Restoring service"
|
||||||
ds restore localhost $SERVICE_NAME || die "Failed to restore service"
|
ds restore localhost $SERVICE_NAME latest || die "Failed to restore service"
|
||||||
|
|
||||||
title "Checking status"
|
title "Checking status"
|
||||||
ds status localhost $SERVICE_NAME || die "Failed to check status"
|
ds status localhost $SERVICE_NAME || die "Failed to check status"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user