2024-08-02 12:09:55 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
bhost="$(hostname -s)"
|
|
|
|
bdate="$(date +"%Y%m%d")"
|
|
|
|
|
|
|
|
if [[ ! -d "/var/backup" ]]; then
|
|
|
|
mkdir /var/backup
|
|
|
|
fi
|
|
|
|
|
|
|
|
pushd /var/backup &>/dev/null || exit 2
|
|
|
|
|
2024-08-02 15:54:47 -04:00
|
|
|
echo "Creating stage4 backup in /var/backup/$bhost-stage4.zst"
|
2024-08-02 12:09:55 -04:00
|
|
|
mkstage4 -s -l -q -C zst \
|
|
|
|
-e "/var/lib/containers/*" \
|
|
|
|
-e "/var/lib/machines/*" \
|
|
|
|
-e "/var/lib/portables/*" \
|
|
|
|
-e "/var/lib/libvirt/*" \
|
|
|
|
-e "/var/cache/binpkgs/*" \
|
2024-08-02 15:57:48 -04:00
|
|
|
-e "/var/backup/*" \
|
2024-08-02 12:09:55 -04:00
|
|
|
-e "/home/*/*" \
|
2024-08-02 15:54:47 -04:00
|
|
|
"$bhost-stage4-$bdate"
|
|
|
|
|
|
|
|
if [[ "$?" -ne 0 ]]; then
|
|
|
|
echo "ERROR: Backup failure"
|
|
|
|
exit 1
|
|
|
|
else
|
2024-08-02 15:55:36 -04:00
|
|
|
if [[ -f "/var/backup/$bhost-stage4.tar.zst" ]]; then
|
|
|
|
rm -f "/var/backup/$bhost-stage4.tar.zst"
|
2024-08-02 15:54:47 -04:00
|
|
|
fi
|
2024-08-02 15:55:36 -04:00
|
|
|
mv "/var/backup/$bhost-stage4-$bdate.tar.zst" "/var/backup/$bhost-stage4.tar.zst"
|
2024-08-02 15:54:47 -04:00
|
|
|
fi
|
2024-08-02 12:09:55 -04:00
|
|
|
|
|
|
|
popd &>/dev/null || exit 2
|