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