Basic backup scripts fixed up
This commit is contained in:
parent
65db093410
commit
c6b19fcbb4
3 changed files with 80 additions and 34 deletions
|
@ -1,26 +1,46 @@
|
||||||
#!/usr/bin/env fish
|
#!/usr/bin/env fish
|
||||||
|
|
||||||
set host rift
|
# deps: fish, zstd, gpg, ssh
|
||||||
set dir /storage/daniel/backups
|
|
||||||
set ext .tar.zstd.gpg
|
set -q HOST || set HOST (head -n 1 /etc/hostname | tr -d '\n')
|
||||||
|
|
||||||
|
# use the backup-host in the ~/.ssh/config as the default backup remote host
|
||||||
|
set -q BACKUP_REMOTE_HOST || set BACKUP_REMOTE_HOST backup-host
|
||||||
|
|
||||||
|
# use a user-specific dir by default to backup to
|
||||||
|
set -q BACKUP_REMOTE_DIR || set BACKUP_REMOTE_DIR "/storage/"(whoami)"/backups/$HOST"
|
||||||
|
|
||||||
|
set BACKUP_FILE_EXT .tar.zstd.gpg
|
||||||
|
|
||||||
if not set -q argv[1]
|
if not set -q argv[1]
|
||||||
echo "No directory provided"
|
echo "No target file or directory provided"
|
||||||
exit 2
|
exit 2
|
||||||
end
|
end
|
||||||
if not test -d $argv[1]
|
|
||||||
echo "Invalid directory given: $argv[1]"
|
set target $argv[1]
|
||||||
|
if not test -d $target
|
||||||
|
echo "Target '$target' is not a directory"
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
set fn (date +%Y%m%d_%H%M%S)(basename $argv[1])
|
|
||||||
pushd (dirname $argv[1])
|
set remote_path
|
||||||
|
|
||||||
|
pushd (dirname $target) >/dev/null
|
||||||
# TODO: progress bar/status?
|
# TODO: progress bar/status?
|
||||||
echo "Streaming PGP encrypted backup of $argv[1] to host rift via ssh at $dir/$fn$ext..."
|
set friendly_target (pwd)
|
||||||
tar cvf - (basename $argv[1]) 2>/dev/null |
|
set path_friendly_target (pwd | cut -c2- | string replace -a / %)
|
||||||
|
set backup_file_name (date +%Y-%m-%d_%H-%M-%S)_"$path_friendly_target"
|
||||||
|
|
||||||
|
set remote_path "$BACKUP_REMOTE_DIR/$backup_file_name$BACKUP_FILE_EXT"
|
||||||
|
echo "Streaming PGP encrypted backup of $friendly_target to SSH host $BACKUP_REMOTE_HOST at $remote_path"
|
||||||
|
ssh $BACKUP_REMOTE_HOST "mkdir -p $BACKUP_REMOTE_DIR"
|
||||||
|
# TODO: progress indicator?
|
||||||
|
tar cf - . |
|
||||||
zstd --ultra -T2 -22 |
|
zstd --ultra -T2 -22 |
|
||||||
gpg --encrypt --recipient daniel@lyte.dev |
|
gpg --encrypt --recipient daniel@lyte.dev |
|
||||||
ssh $host "cat - > $dir/$fn$ext"
|
ssh $BACKUP_REMOTE_HOST "cat - > $remote_path"
|
||||||
popd
|
popd >/dev/null
|
||||||
|
|
||||||
# TODO: checksum?
|
# TODO: checksum?
|
||||||
echo "Uploaded to host rift via ssh at $dir/$fn$ext"
|
echo "Uploaded to host rift via ssh at $remote_path"
|
||||||
echo ' Run `unbackupify '$fn$ext'` to restore!'
|
echo " Run 'unbackupify \"$backup_file_name$BACKUP_FILE_EXT\"' to restore!"
|
||||||
|
|
|
@ -1,18 +1,43 @@
|
||||||
#!/usr/bin/env fish
|
#!/usr/bin/env fish
|
||||||
|
|
||||||
set host rift
|
# deps: fish, zstd, gpg, ssh
|
||||||
set dir /storage/daniel/backups
|
|
||||||
set ext .tar.zstd.gpg
|
|
||||||
|
|
||||||
if not set -q argv[1]
|
set -q HOST || set HOST (head -n 1 /etc/hostname | tr -d '\n')
|
||||||
echo "No backup filename provided"
|
|
||||||
exit 2
|
# use the backup-host in the ~/.ssh/config as the default backup remote host
|
||||||
|
set -q BACKUP_REMOTE_HOST || set BACKUP_REMOTE_HOST backup-host
|
||||||
|
|
||||||
|
# use a user-specific dir by default to backup to
|
||||||
|
set -q BACKUP_REMOTE_DIR || set BACKUP_REMOTE_DIR "/storage/"(whoami)"/backups/$HOST"
|
||||||
|
|
||||||
|
set BACKUP_FILE_EXT .tar.zstd.gpg
|
||||||
|
|
||||||
|
set target $argv[1]
|
||||||
|
if test $target = '--list-backup-files'
|
||||||
|
ssh $BACKUP_REMOTE_HOST "command ls -1 $BACKUP_REMOTE_DIR"
|
||||||
|
exit 0
|
||||||
|
else if test (count $argv) -lt 1
|
||||||
|
echo "No remote backup filename provided (use --list-backup-files to show)"
|
||||||
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: autocomplete?
|
# TODO: autocomplete?
|
||||||
# TODO: checksum?
|
# TODO: checksum?
|
||||||
set fn $argv[1]
|
# TODO: progress indicator?
|
||||||
ssh $host "cat $dir/$fn$ext" |
|
|
||||||
gpg --decrypt |
|
set local_dir (echo $target | awk -F. '{print $1}')
|
||||||
|
mkdir $local_dir || begin
|
||||||
|
echo "Local unbackup directory '$local_dir' exists"
|
||||||
|
exit 2
|
||||||
|
end
|
||||||
|
|
||||||
|
pushd $local_dir >/dev/null
|
||||||
|
|
||||||
|
ssh $BACKUP_REMOTE_HOST "cat $BACKUP_REMOTE_DIR/$target" |
|
||||||
|
gpg --decrypt 2>/dev/null |
|
||||||
zstd --ultra -T2 -22 -dc |
|
zstd --ultra -T2 -22 -dc |
|
||||||
tar -xvf -
|
tar -xf -
|
||||||
echo "Restored!"
|
|
||||||
|
popd >/dev/null
|
||||||
|
|
||||||
|
echo "Restored to $local_dir"
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
font_family iosevkalyte
|
font_family IosevkaLyte
|
||||||
# bold_font Iosevka Heavy
|
bold_font IosevkaLyte Heavy
|
||||||
# italic_font Iosevka Italic
|
italic_font IosevkaLyte Italic
|
||||||
# bold_italic_font Iosevka Heavy Italic
|
bold_italic_font IosevkaLyte Heavy Italic
|
||||||
font_size 11.0
|
font_size 12.5
|
||||||
|
|
||||||
# use `kitty + list-fonts --psnames` to get the font's PostScript name
|
# use `kitty + list-fonts --psnames` to get the font's PostScript name
|
||||||
# font_features IosevkaLyte
|
# font_features IosevkaLyte
|
||||||
|
@ -23,8 +23,9 @@ map ctrl+shift+equal change_font_size all +0.5
|
||||||
map ctrl+shift+minus change_font_size all -0.5
|
map ctrl+shift+minus change_font_size all -0.5
|
||||||
map shift+insert paste_from_clipboard
|
map shift+insert paste_from_clipboard
|
||||||
map ctrl+shift+v paste_from_selection
|
map ctrl+shift+v paste_from_selection
|
||||||
|
map ctrl+shift+c copy_to_clipboard
|
||||||
|
|
||||||
enable_audio_bell no
|
enable_audio_bell yes
|
||||||
|
|
||||||
url_style single
|
url_style single
|
||||||
|
|
||||||
|
|
Reference in a new issue