#!/bin/sh
# 2021-11-10
# revised 2022-01-06 for multiple devices

set -e
set -u

eval "$(ssh pm-rndis cat /etc/deviceinfo)"

if [ -z "${deviceinfo_codename}" ]
then
    echo Cannot device which device is connected!
    exit 1
fi

echo Connected device: $deviceinfo_codename

rsnapshot_conf=/tmp/rsnapshot.backups-pm-${deviceinfo_codename}.conf

cat > $rsnapshot_conf <<EOF
config_version	1.2
snapshot_root	/home/tonyg/src/squeak-phone/devices/${deviceinfo_codename}/backups/home-user
no_create_root	0

cmd_cp		/usr/bin/cp
cmd_rm		/usr/bin/rm
cmd_rsync	/usr/bin/rsync
cmd_ssh	/usr/bin/ssh
cmd_logger	/usr/bin/logger

logfile	/tmp/rsnapshot.backups-pm-${deviceinfo_codename}.log
lockfile	/tmp/rsnapshot.backups-pm-${deviceinfo_codename}.pid

retain		adhoc	10000

verbose		2

one_fs	1

sync_first	1

backup	user@pm-rndis:/home/user	./
EOF

rsnapshot -c ${rsnapshot_conf} sync
rsnapshot -c ${rsnapshot_conf} adhoc
