llanura14Backup.sh 884 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/sh
  2. ZROOT_BASE="zroot"
  3. SSH="/usr/bin/ssh"
  4. ZFS="/sbin/zfs "
  5. REMOTE="davidmarec.ddns.net"
  6. REMOTE_USER="david"
  7. REMOTE_KEY=~david/.ssh/id_ed25519
  8. REMOTE_POOL="dmarec/popeye"
  9. failure()
  10. {
  11. echo ${@}
  12. exit 1
  13. }
  14. ssh-add ${REMOTE_KEY} || failure 'ssh-agent required.'
  15. # getting last snapshot id
  16. # if one cannot trust the snap id one can use creation time
  17. for i in usr JAILS
  18. do
  19. ZROOT="${ZROOT_BASE}/${i}"
  20. ZLAST=`${ZFS} list -o name -Hp -t snap -d 1 ${ZROOT} | cut -d '@' -f 2 | sort | tail -1`
  21. echo '---------------------------------------------------'
  22. echo "sending backup ${ZROOT}@${ZLAST} to ${REMOTE_POOL}"
  23. echo
  24. ${ZFS} send -R -e -L -c ${ZROOT}@${ZLAST} | \
  25. ${SSH} -i ${REMOTE_KEY} ${REMOTE_USER}@${REMOTE} \
  26. ${ZFS} recv -Fdu -o canmount=off -x mountpoint -x logbias -x dedup -x copies ${REMOTE_POOL}
  27. echo '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
  28. done