Linux‎ > ‎

rsync

copy the partition /home from local machine to a remote machine, box2.

rsync -avHx --delete /home/ root@box2:/home

Make a copy of a partition:

rsync -avr --progress --stats /var/ /usr/var/

rsync new files only
rsync -avr --update --progress /web/vs/files/binary-cache/ root@10.110.2.20:/web/vs/files/binary-cache/


This will rsync a cluster from the web nodes.

#!/bin/bash ### BEGIN CONFIGURATION ### CLUSTER="10.0.0.10 10.0.0.20 10.0.0.30 10.0.0.40 10.0.0.50 10.0.0.60 10.0.0.70 10.0.0.80" SOURCE="/usr/drupal_www/" DEST="/var/www/" ### END CONFIGURATION ### # Command usage print_usage() { echo "Usage: $0 [ -y | -c | -l | -h ]" echo echo " -y perform the rsync. The default is to do a dry-run." echo echo " -c show the command that will run on each node, then exit" echo " -l print a list of the available hosts, then exit" echo " -h show this help message, then exit" } # Process command-line flags FLAGS="" SHOW_COMMAND=0 LIST_HOSTS=0 EXECUTE=0 while getopts "yhcl" options; do case $options in y ) EXECUTE=1  ;; c ) SHOW_COMMAND=1  ;; l ) LIST_HOSTS=1  ;; h ) print_usage exit 0  ;; * ) print_usage exit 1  ;; esac done # Generate rsync command DRYRUN="n" if [ $EXECUTE -eq 1 ]; then DRYRUN="" fi COMMAND="rsync -av$DRYRUN --delete --exclude=.ssh --exclude=CVS --exclude=.svn $SOURCE $DEST" # Show the command and exit if -c was given on the command line if [ $SHOW_COMMAND -eq 1 ]; then echo "The following command would be run on all nodes:" echo "$COMMAND" exit 0 fi # Check if each cluster member is alive HOSTS="" for HOST in $CLUSTER; do ping -t 1 -c 1 -s 1 $HOST > /dev/null 2>&1 if [ $? -ne 0 ]; then echo echo "*************************************************" echo "Host: $HOST either does not exist or is down." echo "Process resumes in 5 secs or Control-C to cancel" echo "*************************************************" sleep 5 else HOSTS="$HOSTS $HOST" fi done # Show the host list if -l was given on the command line if [ $LIST_HOSTS -eq 1 ]; then echo "The following hosts are available" echo $HOSTS exit 0; fi # Execute command for HOST in $HOSTS; do echo echo " --- $HOST --- " ssh $HOST "$COMMAND" echo " --- done --- " done wait

Comments