Compare commits

...

3 commits

Author SHA1 Message Date
e7d024f68a bash: Add shorthands to mount client-side encrypted NAS directories 2022-12-29 16:38:53 -05:00
12683853e5 Add scripts for backing up to NAS based on restic 2022-12-29 16:34:31 -05:00
5e5e489d85 bashrc: Add utility function to clamp maximum length of file name
This is useful when synchronizing to an Rclone encrypted remote
2022-12-28 14:13:23 -05:00
3 changed files with 72 additions and 0 deletions

View file

@ -124,3 +124,44 @@ export QT_IM_MODULE=fcitx
export SDL_IM_MODULE=fcitx
export WLR_XWAYLAND=$HOME/.local/bin/Xwayland-noshm
$MACHINE_START_SWAY && [[ -z "$DISPLAY" && $(tty) == /dev/tty1 ]] && exec sway
# Miscellaneous utilities
function clamp_filename() {
[[ -z "$1" ]] && return 1
local len="$1"
for file in *; do
local filename_len=$(echo "$file" | wc -c)
if [ $filename_len -gt $len ]; then
local extension="${file##*.}"
local filename="${filename%.*}"
if [ ${#extension} -gt 5 ]; then
filename="$file"
extension=""
fi
local clamped_filename="$(echo "$file" | cut -c1-$((len - ${#extension})) | iconv -f utf8 -t utf8 -c -)"
if [ ${#extension} -gt 0 ]; then
clamped_filename="$clamped_filename.$extension"
fi
echo "File '$PWD/$file' clamped to '$PWD/$clamped_filename'"
mv "$file" "$clamped_filename"
file="$clamped_filename"
fi
if [ -d "$file" ]; then
pushd "$file" > /dev/null
clamp_filename "$1"
popd > /dev/null
fi
done
}
function open_nas_decrypt() {
gocryptfs -passfile /dev/stdin "$MACHINE_NAS_CIPHER_PATH" "$MACHINE_NAS_DECRYPT_PATH" <<< "$(pass gocrypt show "$MACHINE_NAS_CIPHER_PASS")"
}
function close_nas_decrypt() {
fusermount -u "$MACHINE_NAS_DECRYPT_PATH"
}

View file

@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -e
source ~/.config/restic-backup/config.sh
cleanup() {
pass gocrypt close || true > /dev/null 2>&1
}
trap cleanup EXIT
pass gocrypt close > /dev/null 2>&1 || true
PASS_GOCRYPT_CLOSE_TIMEOUT=2147483648 pass gocrypt open
for dir in ${RESTIC_BACKUP_SUBVOL_PATHS[@]}; do
parent="$(dirname $dir)"
snap="$parent/$(basename $dir)-restic"
echo "snap = $snap"
sudo btrfs subvol delete "$snap" > /dev/null 2>&1 || true
sudo btrfs subvol snap "$dir" "$snap"
restic-wrapper --verbose backup "$snap"
sudo btrfs subvol delete "$snap" || true
done

View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -e
source ~/.config/restic-backup/config.sh
pass gocrypt open || true
sudo restic --password-file /dev/stdin -r "$RESTIC_BACKUP_REPO" $@ <<< $(pass show "$RESTIC_BACKUP_PASS")