Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.3 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #!/bin/sh
  2. # This is a backup script that takes snapshots of your device
  3. # In a Time Machine like fashion. You can add this to root's
  4. # crontab for regular backups
  5. # Config
  6. readonly SSH_HOST=192.168.1.8
  7. readonly SSH_USER=yigit
  8. readonly SSH_KEY="/home/yigit/.ssh/id_skeleton"
  9. readonly RSYNC_PROFILE="$SSH_USER@$SSH_HOST:~/snapshots"
  10. alias ssh_cmd="ssh -i \"$SSH_KEY\" $SSH_USER@$SSH_HOST"
  11. DEVICE=tatooine
  12. OPT="-aPh"
  13. SNAP="$RSYNC_PROFILE/$DEVICE/"
  14. date=$(date "+%I:%M-%d.%m.%Y")
  15. # You should enter absolute paths
  16. DIRS="/home/yigit
  17. /etc
  18. /var/lib
  19. /var/spool
  20. /usr/src/linux"
  21. # Check whether backup server is available on network
  22. timeout 3 ssh -i "$SSH_KEY" $SSH_USER@$SSH_HOST id < /dev/null > /dev/null 2> /dev/null || echo "SSH Failed." || exit
  23. # Run rsync to create snapshot
  24. while IFS= read -r DIR
  25. do
  26. LINK="--link-dest=/home/$SSH_USER/snapshots/tatooine/last$DIR/"
  27. ssh -i "$SSH_KEY" $SSH_USER@$SSH_HOST mkdir -p "~/snapshots/$DEVICE/$date$DIR" < /dev/null
  28. rsync --exclude '.cache' "$@" -e "ssh -i $SSH_KEY" $OPT "$LINK" "$DIR/" "${SNAP}$date$DIR/"
  29. done << EOF
  30. $DIRS
  31. EOF
  32. # Remove symlink to previous snapshot
  33. ssh_cmd rm -f "~/snapshots/$DEVICE/last" < /dev/null
  34. # Create new symlink to latest snapshot for the next backup to hardlink
  35. ssh -i "$SSH_KEY" $SSH_USER@$SSH_HOST ln -s "~/snapshots/$DEVICE/$date" "~/snapshots/$DEVICE/last" < /dev/null