Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2013
962
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.47 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [[ $# -ne 3 || ( "$1" != "backup" && "$1" != "restore") ]]; then
  4.     echo "Usage: $0 [backup|restore] source destination"
  5.     exit 1
  6. fi
  7.  
  8. date=`date "+%Y-%m-%d-%H-%M-%S"`
  9. SRC="$2"
  10. DST="$3"
  11.  
  12. if [ ! -d "$SRC" ]; then
  13.     echo "$SRC" is not a directory or does not exist
  14.     exit 1
  15. fi
  16. if [ ! -d "$DST" ]; then
  17.     echo "$DST" is not a directory or does not exist
  18.     exit 1
  19. fi
  20.  
  21. function rsync_backup() {
  22.     # $1 = SRC, $2 = DST, $3 = date
  23.     SRC="$1"
  24.     DST="$2"
  25.     date="$3"
  26.  
  27.     rsync --recursive --links --perms --times --group --owner --devices --specials --verbose --delete --numeric-ids \
  28.     --exclude={/dev/*,/proc/*,/mnt/*,/media/*,/sys/*,/tmp/*,/run/*,/home/*/.gvfs,/home/*/.cache,/var/lib/pacman/sync/*,/var/cache/pacman/pkg/*,/home/*/tmp/*,/home/*/VirtualBox\ VMs,/home/*/.dbus,/swapfile,/home/*/.thumbnails,/home/*/.wine,/home/*/.davfs2/cache,/home/*/.gksu.lock,/home/*/.gmrun_history,/home/*/Downloads/*,/home/*/.local/share/Trash} \
  29.     --link-dest="`readlink -f "$DST"`/Latest" \
  30.     $SRC $DST/Processing-$date \
  31.     && cd $DST \
  32.     && mv Processing-$date $date \
  33.     && rm -f Latest \
  34.     && ln -s $date Latest
  35. }
  36.  
  37. function rsync_restore() {
  38.     # $1 = SRC, $2 = DST, $3 = date
  39.     SRC="$1"
  40.     DST="$2"
  41.     date="$3"
  42.  
  43.     rsync --recursive --links --perms --times --group --owner --devices --specials --verbose --delete --numeric-ids \
  44.     $SRC $DST
  45. }
  46.  
  47. if [[ $1 == "backup" ]]; then
  48.     rsync_backup $SRC $DST $date
  49. fi
  50. if [[ $1 == "restore" ]]; then
  51.     rsync_restore $SRC $DST $date
  52. fi
  53.  
  54. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement