Files
scripts/backup
2021-06-26 16:52:22 +02:00

39 lines
795 B
Bash
Executable File

#!/bin/bash
tempDir=/tmp/backup
mountRemote() {
rclone mount schulev: "$tempDir" --daemon
}
umountRemote() {
umount "$tempDir"
}
case $1 in
restore)
mountRemote
find "$tempDir" -type f | xargs -n 1 tar -xf
umountRemote
;;
backup)
mountRemote
declare -A hashes
while IFS= read -r file; do
hash="$(echo -n "$file" | openssl dgst -binary -sha256 | openssl base64 | sed -e 's/\//@/g')"
hashes[s]=0
file_hash="$tempDir/$hash"
hashes[$hash]=0
if [[ ! -f "$file_hash" || $(tar -df "$file_hash") ]]; then
tar -cf "$file_hash" "$file"
fi
done < <(find -type f,l; find -type d -empty)
cd "$tempDir"
for file in *; do
if [ ! -v hashes[$file] ]; then
rm "$file"
fi
done
umountRemote
;;
*)
echo "use backup or restore as argument"
;;
esac