more scripts
This commit is contained in:
38
backup
Executable file
38
backup
Executable file
@ -0,0 +1,38 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user