Skip to content

Instantly share code, notes, and snippets.

@gjaekel
Created February 6, 2026 07:23
Show Gist options
  • Select an option

  • Save gjaekel/da9e60c82c87923e100ff006c3eb6094 to your computer and use it in GitHub Desktop.

Select an option

Save gjaekel/da9e60c82c87923e100ff006c3eb6094 to your computer and use it in GitHub Desktop.
Restic Remote Backup Script to be called on Backup Server
#!/bin/bash
#
# 20231229/gj
# 20240208/gj root user check
# 20260206/gj add repository option
if [ -z "$1" ]; then
cat >&2 <<-EOT
syntax : $0 <host> [repository]
purpose: - wol host if required
- do a restic backup to the ubuntu repository
- suspend again in case
options:
repository remote repository (i.e. script extention) to use, default is `ubuntu`
EOT
exit -1
fi
[ "$EUID" -ne 0 ] && echo "must be run as root user!" >&2 && exit -1
REMOTE="$1"; shift
REPOSITORY="$1"; shift
[ -z "$REPOSITORY" ] && REPOSITORY="ubuntu"
IS_PINGABLE () {
ping -c1 $1 >/dev/null
}
echo -n "pinging \"$REMOTE\" ..."
if ! IS_PINGABLE $REMOTE; then
echo -en ", no answer.\nwaking \"$REMOTE\" ..."
_wakeonlan $REMOTE >/dev/null
for i in {1..5}; do
echo -n "[$i]"
IS_PINGABLE $REMOTE && break # true
done; RC=$?
echo -en "\nhost \"$REMOTE\""
[ $RC -ne 0 ] && echo " don't wake up!" && exit 1
WAKED=$i
fi
echo " is up."
echo "starting backup to \"$REPOSITORY\" ..."
ssh root@$REMOTE "/import/gateway/backup/restic/_restic.$REPOSITORY backup / $@ && [ "$WAKED" ] && echo "suspending ..." && systemctl suspend"
echo "backup finished."
if [ "$WAKED" ]; then
echo -n "pinging \"$REMOTE\" ..."
for i in {1..20}; do
echo -n "[$i]"
! IS_PINGABLE $REMOTE && break # true
sleep 3
done; RC=$?
echo -en "\nhost \"$REMOTE\""
[ $RC -ne 0 ] && echo " is still up!" || echo "is down again."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment