Advertisement
freephile

Rsync User Home Directories

May 25th, 2013
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.78 KB | None | 0 0
  1. cat /root/bin/copy.home.dirs.sh
  2. #!/bin/bash -e
  3. # run bash with -e to exit on errors
  4.  
  5. # create a function that we can attach a signal to
  6. # in case we want to stop this script
  7. # otherwise if we press Ctrl-C, it will just continue
  8. # with the next iteration in the loop
  9. cleanup ()
  10. {
  11. kill -s SIGTERM $!
  12. exit 0
  13. }
  14. # now set the trap
  15. trap cleanup SIGINT SIGTERM
  16. SOURCE=a.example.com
  17. LOGFILE=home.copy.log
  18.  
  19. # we will use a prepared file 'users' whose contents are a list of users, one user per line
  20. while read USER
  21. do echo "Working on $USER" | tee -a $LOGFILE
  22. TIMING="$(time ( rsync -avSHPz root@$SOURCE:/home/$USER/ /nas_home/$USER/ ) 2>&1 1>/dev/null )"
  23. echo $TIMING | tee -a $LOGFILE
  24. echo "/home/$USER copied to new NAS" | tee -a $LOGFILE
  25. echo "" | tee -a $LOGFILE
  26. done < "users"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement