sh.zio.backup: add ability to run arbitrary restic commands
parent
229cee2f31
commit
82b10ba696
|
@ -21,18 +21,19 @@ function download_restic() {
|
|||
restic_path="/tmp/restic-$restic_version"
|
||||
restic_archive_path="${restic_path}_$(date +%s).${restic_download_url##*.}"
|
||||
|
||||
say info "Downloading Restic ($restic_version)..."
|
||||
if [[ ! -f "$restic_path" ]]; then
|
||||
say info "Downloading Restic ($restic_version)..."
|
||||
|
||||
rm -f "$restic_path"
|
||||
curl -L -s -o "$restic_archive_path" "$restic_download_url"
|
||||
bzip2 -dc "$restic_archive_path" > "$restic_path"
|
||||
rm -f "$restic_archive_path"
|
||||
|
||||
curl -L -s -o "$restic_archive_path" "$restic_download_url"
|
||||
bzip2 -dc "$restic_archive_path" > "$restic_path"
|
||||
rm -f "$restic_archive_path"
|
||||
chmod +x "$restic_path"
|
||||
|
||||
chmod +x "$restic_path"
|
||||
|
||||
if [[ ! "$(echo "$("$restic_path" version)")" == "restic $restic_version"* ]]; then
|
||||
die "Unexpected output from '$restic_path version'"
|
||||
if [[ ! "$(echo "$("$restic_path" version)")" == "restic $restic_version"* ]]; then
|
||||
die "Unexpected output from '$restic_path version'"
|
||||
rm -f "$restic_path"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -60,7 +61,7 @@ function invoke_restic() {
|
|||
if [[ -z $command ]]; then
|
||||
say warning "No command specified. Not running"
|
||||
elif [[ $command == "self-update" ]]; then
|
||||
say warning "Command 'self-update' not supported. Not running"
|
||||
say warning "Command '$command' not supported. Not running"
|
||||
else
|
||||
"$restic_path" \
|
||||
--cache-dir "$cache_dir" \
|
||||
|
@ -159,41 +160,46 @@ download_restic 0.16.0
|
|||
test_file "$restic_repo_file"
|
||||
test_file "$restic_repo_passwd_file"
|
||||
|
||||
say info "Running backup scripts..."
|
||||
if [[ -z "$1" ]]; then
|
||||
say info "Running backup scripts..."
|
||||
|
||||
if ! [[ "$(ls -A $backup_scripts_dir)" ]]; then
|
||||
die "No scripts found in '$backup_scripts_dir'"
|
||||
if ! [[ "$(ls -A $backup_scripts_dir)" ]]; then
|
||||
die "No scripts found in '$backup_scripts_dir'"
|
||||
fi
|
||||
|
||||
for backup_script in $backup_scripts_dir/*; do
|
||||
backup_script_filename="$(basename "$backup_script")"
|
||||
backup_script_name="${backup_script_filename%.*}"
|
||||
backup_script_name_length="${#backup_script_name}"
|
||||
|
||||
say primary "-[$backup_script_name]$(repeat "-" $((80-3-$backup_script_name_length)))"
|
||||
chmod +x "$backup_script"
|
||||
|
||||
export -f backup_dir
|
||||
export -f die
|
||||
export -f forget_backup
|
||||
export -f get_config_dir
|
||||
export -f invoke_restic
|
||||
export -f prune_backup
|
||||
export -f say
|
||||
export -f start_service
|
||||
export -f stop_service
|
||||
export -f test_file
|
||||
export backup_scripts_dir
|
||||
export cache_dir
|
||||
export host
|
||||
export restic_repo_file
|
||||
export restic_repo_passwd_file
|
||||
export restic_path
|
||||
export secrets_dir
|
||||
|
||||
"$backup_scripts_dir/$backup_script_filename"
|
||||
done
|
||||
|
||||
say primary "$(repeat "-" 80)"
|
||||
else
|
||||
command="$1"
|
||||
arguments="${@:2}"
|
||||
say info "Running: $restic_path $command $arguments"
|
||||
invoke_restic $command $arguments
|
||||
fi
|
||||
|
||||
for backup_script in $backup_scripts_dir/*; do
|
||||
backup_script_filename="$(basename "$backup_script")"
|
||||
backup_script_name="${backup_script_filename%.*}"
|
||||
backup_script_name_length="${#backup_script_name}"
|
||||
|
||||
say primary "-[$backup_script_name]$(repeat "-" $((80-3-$backup_script_name_length)))"
|
||||
chmod +x "$backup_script"
|
||||
|
||||
export -f backup_dir
|
||||
export -f die
|
||||
export -f forget_backup
|
||||
export -f get_config_dir
|
||||
export -f invoke_restic
|
||||
export -f prune_backup
|
||||
export -f say
|
||||
export -f start_service
|
||||
export -f stop_service
|
||||
export -f test_file
|
||||
export backup_scripts_dir
|
||||
export cache_dir
|
||||
export host
|
||||
export restic_repo_file
|
||||
export restic_repo_passwd_file
|
||||
export restic_path
|
||||
export secrets_dir
|
||||
|
||||
"$backup_scripts_dir/$backup_script_filename"
|
||||
done
|
||||
|
||||
say primary "$(repeat "-" 80)"
|
||||
|
||||
#sudo rm -f "$restic_path"
|
||||
|
|
Loading…
Reference in New Issue