md
This commit is contained in:
54
backup
54
backup
@ -1,38 +1,18 @@
|
||||
#!/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
|
||||
cd /media/hdd1/data
|
||||
if [[ -d .snapshots/rclone ]]; then
|
||||
echo "last backup not finnished" > /dev/stderr
|
||||
exit 1
|
||||
fi
|
||||
getfacl -R * > mrgeorgen/backup/perms
|
||||
SNAPSHOT="/media/hdd1/data-snapshots/rclone"
|
||||
btrfs su sn /media/hdd1/data "$SNAPSHOT"
|
||||
cd "$SNAPSHOT"
|
||||
rclone sync -l --retries 10 --tpslimit 10 --user-agent "ISV|rclone|rclone/v1.42" . schulev: --exclude "/mrgeorgen/Medien/**" --exclude "/.snapshots/**" --exclude /.snapshots/ --exclude "/mrgeorgen/backup/natur/**" --exclude /mrgeorgen/backup/natur/ --exclude "/mrgeorgen/.cache/minecraft-mod-packager/**" |&
|
||||
grep -v "Can't transfer non file/directory" | (
|
||||
err=`cat`
|
||||
if [[ $(echo "$err" |grep "ERROR : Attempt 10/10 failed with") ]]; then
|
||||
echo "$err" > /dev/stderr
|
||||
fi
|
||||
)
|
||||
btrfs su de "$SNAPSHOT"
|
||||
|
||||
Reference in New Issue
Block a user