Created
March 8, 2018 02:07
-
-
Save cnrd/40b7c6d79d5d645b21eb2da561c17b91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
## Configs ## | |
ZFSSNAPSHOTNAME="duplicacy" | |
mountSnapshots () { | |
mkdir -p "/mnt/$ZFSSNAPSHOTNAME" | |
mount -t zfs "$ZFSSNAPSHOTBASE@$ZFSSNAPSHOTNAME" "/mnt/$ZFSSNAPSHOTNAME" | |
while read -r line | |
do | |
MOUNTPATH=$(echo "$line" | sed "s/$ESCAPEDZFSSNAPSHOTBASE\///" | sed "s/@$ZFSSNAPSHOTNAME//") | |
if [ -d "/mnt/$ZFSSNAPSHOTNAME/$MOUNTPATH" ]; then | |
mount -t zfs "$line" "/mnt/$ZFSSNAPSHOTNAME/$MOUNTPATH" | |
fi | |
done < <(zfs list -t snapshot | grep "$ZFSSNAPSHOTNAME" | grep "$ZFSSNAPSHOTBASE" | grep -v "$ZFSSNAPSHOTBASE/\." | grep -o "$ZFSSNAPSHOTBASE/[0-9,a-z,A-Z,/,[:space:]]*@$ZFSSNAPSHOTNAME" | sed 's/[[:space:]]*$//') | |
} | |
unmountSnapshots () { | |
while read -r line | |
do | |
MOUNTPATH=$(echo "$line" | sed "s/$ESCAPEDZFSSNAPSHOTBASE\///" | sed "s/@$ZFSSNAPSHOTNAME//") | |
if [ -d "/mnt/$ZFSSNAPSHOTNAME/$MOUNTPATH" ]; then | |
umount "/mnt/$ZFSSNAPSHOTNAME/$MOUNTPATH" | |
fi | |
done < <(zfs list -t snapshot | grep "$ZFSSNAPSHOTNAME" | grep "$ZFSSNAPSHOTBASE" | grep -v "$ZFSSNAPSHOTBASE/\." | grep -o "$ZFSSNAPSHOTBASE/[0-9,a-z,A-Z,/,[:space:]]*@$ZFSSNAPSHOTNAME" | sed 's/[[:space:]]*$//' | tail -r) | |
umount "/mnt/$ZFSSNAPSHOTNAME" | |
rmdir "/mnt/$ZFSSNAPSHOTNAME" | |
} | |
exitCleanup () { | |
trap SIGINT | |
cd "/" | |
unmountSnapshots | |
zfs destroy -r "$ZFSSNAPSHOTBASE@$ZFSSNAPSHOTNAME" | |
rm $PIDFILE | |
exit | |
} | |
createPIDFile () { | |
if [ -f $PIDFILE ] | |
then | |
PID=$(cat $PIDFILE) | |
ps -p $PID > /dev/null 2>&1 | |
if [ $? -eq 0 ] | |
then | |
echo "Process already running" | |
exit 1 | |
else | |
## Process not found assume not running | |
echo $$ > $PIDFILE | |
if [ $? -ne 0 ] | |
then | |
echo "Could not create PID file" | |
exit 1 | |
fi | |
fi | |
else | |
echo $$ > $PIDFILE | |
if [ $? -ne 0 ] | |
then | |
echo "Could not create PID file" | |
exit 1 | |
fi | |
fi | |
} | |
if [ $# -eq 1 ] | |
then | |
BASENAME=$(basename $1) | |
RUNNAME="$ZFSSNAPSHOTNAME-$BASENAME" | |
ZFSSNAPSHOTBASE=$(zfs list | grep "$BASENAME" | grep -v "$BASENAME/" | awk '{print $1}') | |
ESCAPEDZFSSNAPSHOTBASE=$(echo "$ZFSSNAPSHOTBASE" | sed 's/\//\\\//') | |
PIDFILE=/var/lock/$RUNNAME.pid | |
ISOTIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | |
YEAR=$(date -u +"%Y") | |
createPIDFile | |
zfs snapshot -r "$ZFSSNAPSHOTBASE@$ZFSSNAPSHOTNAME" | |
trap "exitCleanup" INT | |
mountSnapshots | |
# Do tha backup dance! | |
cd "/mnt/$ZFSSNAPSHOTNAME" | |
duplicacy -log backup -threads 10 -stats >> "/var/log/$RUNNAME.log" | |
cd "/" | |
unmountSnapshots | |
zfs destroy -r "$ZFSSNAPSHOTBASE@$ZFSSNAPSHOTNAME" | |
rm $PIDFILE | |
else | |
echo "Argument should be: path remote" | |
fi |
No you can just ignore the second parameter
How does it know where to send the backups?
root@freenas:~ # ./duplicacy_freebsd_x64_2.2.3 backup --help
NAME:
duplicacy backup - Save a snapshot of the repository to the storage
USAGE:
duplicacy backup [command options]
OPTIONS:
-hash detect file differences by hash (rather than size and timestamp)
-t <tag> assign a tag to the backup
-stats show statistics during and after backup
-threads <n> number of uploading threads
-limit-rate <kB/s> the maximum upload rate (in kilobytes/sec)
-dry-run dry run for testing, don't backup anything. Use with -stats and -d
-vss enable the Volume Shadow Copy service (Windows and macOS using APFS only)
-vss-timeout <timeout> the timeout in seconds to wait for the Volume Shadow Copy operation to complete
-storage <storage name> backup to the specified storage instead of the default one
-enum-only enumerate the repository recursively and then exit
root@freenas:~ #
I don't see where the '-storage' option has been defined.
After reading the docs again I am assuming I do an 'init' in the root of the data to be backed up and the .duplicity directory is then available from within the ZFS snapshot. The preferences file would then have the storage URL and other metadata to allow the backup to run.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No you can just ignore the second parameter