btrfs-backup 744 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/sh
  2. usage () {
  3. cat <<EOF>&2
  4. Usage: ${0##*/} SOURCE TARGET
  5. Synchronize all the snapshots in the SOURCE/.snapshots to TARGET/.snapshots.
  6. EOF
  7. }
  8. if [ $# -ne 2 ]; then
  9. usage
  10. exit 1
  11. fi
  12. SOURCE="$1"
  13. TARGET="$2"
  14. for i in "$SOURCE"/.snapshots/*; do
  15. parent=""
  16. target_i="$TARGET/.snapshots/$(basename "$i")"
  17. for j in "$i"/*; do
  18. if [ ! -e "$target_i/$(basename "$j")" ]; then
  19. if [ -z "$parent" ] ; then
  20. echo "Sending '$j' to '$target_i'..."
  21. sudo btrfs send "$j" | sudo btrfs receive "$target_i"
  22. else
  23. echo "Sending '$j' to '$target_i' with parent '$parent'..."
  24. sudo btrfs send -p "$parent" "$j" | sudo btrfs receive "$target_i"
  25. fi
  26. fi
  27. parent="$j"
  28. done
  29. ## Unset parent for next "i" subvolume.
  30. parent=""
  31. done