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
|
||||
|
||||
set host rift
|
||||
set dir /storage/daniel/backups
|
||||
set ext .tar.zstd.gpg
|
||||
# deps: fish, zstd, gpg, ssh
|
||||
|
||||
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]
|
||||
echo "No directory provided"
|
||||
echo "No target file or directory provided"
|
||||
exit 2
|
||||
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
|
||||
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?
|
||||
echo "Streaming PGP encrypted backup of $argv[1] to host rift via ssh at $dir/$fn$ext..."
|
||||
tar cvf - (basename $argv[1]) 2>/dev/null |
|
||||
zstd --ultra -T2 -22 |
|
||||
gpg --encrypt --recipient daniel@lyte.dev |
|
||||
ssh $host "cat - > $dir/$fn$ext"
|
||||
popd
|
||||
set friendly_target (pwd)
|
||||
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 |
|
||||
gpg --encrypt --recipient daniel@lyte.dev |
|
||||
ssh $BACKUP_REMOTE_HOST "cat - > $remote_path"
|
||||
popd >/dev/null
|
||||
|
||||
# TODO: checksum?
|
||||
echo "Uploaded to host rift via ssh at $dir/$fn$ext"
|
||||
echo ' Run `unbackupify '$fn$ext'` to restore!'
|
||||
echo "Uploaded to host rift via ssh at $remote_path"
|
||||
echo " Run 'unbackupify \"$backup_file_name$BACKUP_FILE_EXT\"' to restore!"
|
||||
|
|
|
@ -1,18 +1,43 @@
|
|||
#!/usr/bin/env fish
|
||||
|
||||
set host rift
|
||||
set dir /storage/daniel/backups
|
||||
set ext .tar.zstd.gpg
|
||||
# deps: fish, zstd, gpg, ssh
|
||||
|
||||
if not set -q argv[1]
|
||||
echo "No backup filename provided"
|
||||
exit 2
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
# TODO: autocomplete?
|
||||
# TODO: checksum?
|
||||
set fn $argv[1]
|
||||
ssh $host "cat $dir/$fn$ext" |
|
||||
gpg --decrypt |
|
||||
zstd --ultra -T2 -22 -dc |
|
||||
tar -xvf -
|
||||
echo "Restored!"
|
||||
# TODO: progress indicator?
|
||||
|
||||
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 |
|
||||
tar -xf -
|
||||
|
||||
popd >/dev/null
|
||||
|
||||
echo "Restored to $local_dir"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
font_family iosevkalyte
|
||||
# bold_font Iosevka Heavy
|
||||
# italic_font Iosevka Italic
|
||||
# bold_italic_font Iosevka Heavy Italic
|
||||
font_size 11.0
|
||||
font_family IosevkaLyte
|
||||
bold_font IosevkaLyte Heavy
|
||||
italic_font IosevkaLyte Italic
|
||||
bold_italic_font IosevkaLyte Heavy Italic
|
||||
font_size 12.5
|
||||
|
||||
# use `kitty + list-fonts --psnames` to get the font's PostScript name
|
||||
# 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 shift+insert paste_from_clipboard
|
||||
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
|
||||
|
||||
|
|
Reference in a new issue