autobackup

Automatically choose backup location and perform backups using rsync
git clone git://jacobedwards.org/autobackup
Log | Files | Refs | README | LICENSE

autobackup_recieve (753B)


      1 #!/bin/sh
      2 # Copyright 2023 Jacob R. Edwards <jacob@jacobedwards.org>
      3 # Licensed under OpenBSD's ISC license; see LICENSE
      4 #
      5 # Autobackup server.
      6 
      7 printenv DEBUG >/dev/null &&
      8 	set -x
      9 
     10 set -e
     11 
     12 base="$(dirname $0)"
     13 config=/etc/autobackup
     14 
     15 ! test -f "$config" && {
     16 	echo 'No config' 1>&2
     17 	exit 1
     18 }
     19 
     20 case $# in
     21 (0)
     22 	echo "usage: [rsync-args] host" 1>&2
     23 	exit 1
     24 esac
     25 
     26 IFS='
     27 '
     28 host="$(eval echo "$"{$#})"
     29 dir="$("$base"/autobackup_pick "$host" $(<"$config"))"
     30 ! test "$dir" && {
     31 	echo 'No dir' 1>&2
     32 	exit 1
     33 }
     34 path="$dir/mirrors/$host"
     35 set -- $(echo "$*" | sed "\${i\\
     36 $path
     37 d;}")
     38 
     39 echo "Backing up to '$path'" 1>&2
     40 /usr/local/bin/rsync "$@" || :
     41 status=$?
     42 
     43 echo "Logging mirror (status $status)" 1>&2
     44 "$base"/autobackup_log "$host" "$dir" $status
     45 exit $status