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_archive_path="${restic_path}_$(date +%s).${restic_download_url##*.}"
|
||||
|
||||
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"
|
||||
|
@ -33,6 +32,8 @@ function download_restic() {
|
|||
|
||||
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,13 +160,14 @@ 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
|
||||
if ! [[ "$(ls -A $backup_scripts_dir)" ]]; then
|
||||
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_name="${backup_script_filename%.*}"
|
||||
backup_script_name_length="${#backup_script_name}"
|
||||
|
@ -192,8 +194,12 @@ for backup_script in $backup_scripts_dir/*; do
|
|||
export secrets_dir
|
||||
|
||||
"$backup_scripts_dir/$backup_script_filename"
|
||||
done
|
||||
done
|
||||
|
||||
say primary "$(repeat "-" 80)"
|
||||
|
||||
#sudo rm -f "$restic_path"
|
||||
say primary "$(repeat "-" 80)"
|
||||
else
|
||||
command="$1"
|
||||
arguments="${@:2}"
|
||||
say info "Running: $restic_path $command $arguments"
|
||||
invoke_restic $command $arguments
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue