34 lines
795 B
Bash
34 lines
795 B
Bash
#!/bin/sh
|
|
|
|
set -eu
|
|
umask 077
|
|
|
|
mountpoint_dir='/mnt/wasabi-data-crypt'
|
|
destination_dir="$mountpoint_dir/pass"
|
|
timestamp=$(date +%s)
|
|
copied=0
|
|
|
|
if ! mountpoint -q "$mountpoint_dir"; then
|
|
echo "Password backup aborted: $mountpoint_dir is not mounted" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! [ -d "$destination_dir" ]; then
|
|
echo "Password backup aborted: $destination_dir does not exist" >&2
|
|
exit 1
|
|
fi
|
|
|
|
for source_file in ./*.kdbx; do
|
|
[ -e "$source_file" ] || continue
|
|
filename=${source_file#./}
|
|
cp -- "$source_file" "$destination_dir/$timestamp-$filename"
|
|
printf 'Backed up %s\n' "$filename"
|
|
copied=$((copied + 1))
|
|
done
|
|
|
|
if [ "$copied" -eq 0 ]; then
|
|
echo 'Password backup aborted: no .kdbx files found' >&2
|
|
exit 1
|
|
fi
|
|
|
|
printf 'Password backup complete: %s file(s) copied to %s\n' "$copied" "$destination_dir"
|