49 lines
1.3 KiB
Bash
Executable file
49 lines
1.3 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
CURRENT_DATE=$(date +"%Y%m%d")
|
|
DATE_PRETTY=$(date)
|
|
HOST="maru"
|
|
|
|
create_snapshot () {
|
|
logger -p user.info -t schnapps_backup "Creating schnapps backup for host ${HOST}"
|
|
/usr/bin/schnapps create -t single "Export snapshot - ${CURRENT_DATE}"
|
|
sleep 1 # To make sure the lock is removed
|
|
snapshot_id=$(/usr/bin/schnapps list -j | /usr/bin/jq '.["snapshots"][-1].number')
|
|
if /usr/bin/schnapps upload "${snapshot_id}" > /dev/null;
|
|
then
|
|
logger -p user.info -t schnapps_backup "Snapshot for host ${HOST} created successfully"
|
|
return 0
|
|
else
|
|
logger -p user.err "Snapshot creation for host ${HOST} failed"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
if ! create_snapshot;
|
|
then
|
|
exit 1
|
|
fi
|
|
|
|
current_snapshots=$(/usr/bin/schnapps rlist)
|
|
|
|
read -r -d '' TEMPLATE << EOF
|
|
From: Backup Robot <notify@dennogumi.org>
|
|
To: einar@heavensinferno.net
|
|
X-Notification-System: ${HOST}
|
|
Subject: [${CURRENT_DATE}] TurrisOS backup created for host ${HOST}
|
|
|
|
Hello,
|
|
|
|
the schnapps backup has been created successfully on date ${DATE_PRETTY}.
|
|
|
|
Currently-available snapshots:
|
|
|
|
${current_snapshots}
|
|
|
|
Note that snapshots older than 30 days are automatically deleted.
|
|
|
|
--
|
|
Automated notification system
|
|
EOF
|
|
|
|
echo "$TEMPLATE" | msmtp --from=notify@dennogumi.org einar@heavensinferno.net,einar@mailbox.org
|