Guest User

Untitled

a guest
Jan 19th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Root user check
  4. if [[ $EUID -ne 0 ]]; then
  5. echo You must be root to execute this script!
  6. exit 1
  7. fi
  8.  
  9. SNAPS=.snapshots
  10. SNAPS_DIR=/$SNAPS
  11.  
  12. # Snaps folder check
  13. if [ ! -d $SNAPS_DIR ]; then
  14. mkdir $SNAPS_DIR
  15. fi
  16.  
  17. btrfs_backup_func(){
  18. DEST=$1
  19. CONFIG=$2
  20.  
  21. custom_echo "$DEST ($CONFIG) backup started"
  22.  
  23. # If it already exists, remove it first
  24. if btrfs subvolume list / | grep $SNAPS/$CONFIG; then
  25. btrfs subvolume delete $SNAPS_DIR/$CONFIG
  26. fi
  27.  
  28. btrfs subvolume snapshot -r $DEST $SNAPS_DIR/$CONFIG \
  29. || custom_echo "ERROR! Check the output."
  30.  
  31. custom_echo "$DEST ($CONFIG) backup terminated"
  32. custom_echo "Location: $SNAPS_DIR/$CONFIG"
  33. }
  34.  
  35. custom_echo(){
  36. echo -e "\033[1;36m==> $*\033[0m"
  37. }
  38.  
  39.  
  40. # HOME
  41. btrfs_backup_func /home home
  42.  
  43. # Empty line
  44. echo
  45.  
  46. # ROOT
  47. btrfs_backup_func / root
  48.  
  49. echo
  50. echo
  51.  
  52. # Print all subvolumes
  53. custom_echo "BTRFS updated subvolumes list:"
  54. btrfs subvolume list /
Add Comment
Please, Sign In to add comment