add weird btrfs backup script
This commit is contained in:
parent
30c9cf4ba3
commit
a14d55c546
2 changed files with 64 additions and 0 deletions
42
bash/bingus-bak/bak.sh
Executable file
42
bash/bingus-bak/bak.sh
Executable file
|
@ -0,0 +1,42 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
if ssh takyon sudo -u bingus test -e /opt/bingus-files/files_snapshots/current; then
|
||||||
|
echo 'Error: an operation is already ongoing' >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p baks
|
||||||
|
|
||||||
|
ssh takyon sudo -u bingus btrfs subvol snapshot -r \
|
||||||
|
/opt/bingus-files/files \
|
||||||
|
/opt/bingus-files/files_snapshots/current
|
||||||
|
|
||||||
|
if ssh takyon sudo -u bingus test -e /opt/bingus-files/files_snapshots/last; then
|
||||||
|
echo "taking incremental backup" >&2
|
||||||
|
out=baks/"$(date --rfc-3339=seconds)"
|
||||||
|
ssh takyon sudo btrfs send \
|
||||||
|
-p /opt/bingus-files/files_snapshots/last \
|
||||||
|
/opt/bingus-files/files_snapshots/current \
|
||||||
|
--compressed-data > "$out"
|
||||||
|
du -h "$out"
|
||||||
|
echo "removing parent" >&2
|
||||||
|
ssh takyon sudo -u bingus btrfs property set -ts /opt/bingus-files/files_snapshots/last ro false
|
||||||
|
ssh takyon sudo -u bingus btrfs subvol delete /opt/bingus-files/files_snapshots/last
|
||||||
|
else
|
||||||
|
echo "taking first copy" >&2
|
||||||
|
ssh takyon sudo btrfs send \
|
||||||
|
/opt/bingus-files/files_snapshots/current \
|
||||||
|
--compressed-data > baks/epoch
|
||||||
|
du -h baks/epoch
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "renaming current to last" >&2
|
||||||
|
|
||||||
|
ssh takyon sudo -u bingus mv \
|
||||||
|
/opt/bingus-files/files_snapshots/current \
|
||||||
|
/opt/bingus-files/files_snapshots/last
|
||||||
|
|
||||||
|
echo "backup complete" >&2
|
||||||
|
|
22
bash/bingus-bak/restore.sh
Executable file
22
bash/bingus-bak/restore.sh
Executable file
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
if [[ -e restoration ]]; then
|
||||||
|
echo 'Error: an operation is already ongoing' >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir restoration
|
||||||
|
|
||||||
|
echo "restoring baks/epoch" >&2
|
||||||
|
sudo btrfs receive restoration -f baks/epoch
|
||||||
|
|
||||||
|
find baks -maxdepth 1 -type f | sort | head -n-1 | while read -r file; do
|
||||||
|
echo "restoring $file" >&2
|
||||||
|
mv restoration/{current,last}
|
||||||
|
sudo btrfs receive restoration -f "$file"
|
||||||
|
sudo btrfs subvol delete restoration/last
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "restoration complete" >&2
|
Loading…
Reference in a new issue