循环增量备份
- #!/bin/bash
- ###################################
- # $Id: backup 379 2012-04-02 08:43:42Z netkiller $
- # Author: netkiller@msn.com
- # Home: http://netkiller.github.com
- ###################################
- BACKUP_DIR=/backup/www
- ####################################
- LOGFILE='/var/tmp/test.log'
- RSYNC="rsync"
- WEEK=$(date -u +%A)
- RSYNC_OPTS="-auz --delete --log-file=$LOGFILE"
- ####################################
- test ! -w $BACKUP_DIR && echo "Error: $BACKUP_DIR is un-writeable." && exit 0
- umask 0077
- for domain in $(ls -1 /www)
- do
- test ! -d "$BACKUP_DIR/$domain" && mkdir -p "$BACKUP_DIR/$domain"
- echo "$domain:"
- for host in $(ls -1 /www/$domain)
- do
- echo " - $host"
- backup_dir=$BACKUP_DIR/$domain/$host/$WEEK
- mkdir -p ${backup_dir}
- $RSYNC $RSYNC_OPTS /www/$domain/$host/* $backup_dir
- done
- done
全备份
- #!/bin/bash
- ###################################
- # $Id: backup 379 2012-04-02 08:43:42Z netkiller $
- # Author: netkiller@msn.com
- # Home: http://netkiller.github.com
- ###################################
- BACKUP_DIR=/backup/www
- #Number of copies
- COPIES=30
- ####################################
- TAR='tar'
- RSYNC="rsync"
- TIMEPOINT=$(date -u +%Y-%m-%d)
- TAR_OPTS="zcf"
- ####################################
- test ! -w $BACKUP_DIR && echo "Error: $BACKUP_DIR is un-writeable." && exit 0
- umask 0077
- for domain in $(ls -1 /www)
- do
- test ! -d "$BACKUP_DIR/$domain" && mkdir -p "$BACKUP_DIR/$domain"
- echo "$domain:"
- for host in $(ls -1 /www/$domain)
- do
- echo " - $host"
- backup_dir=$BACKUP_DIR/$domain/$host/$WEEK
- mkdir -p ${backup_dir}
- $TAR $TAR_OPTS $BACKUP_DIR/$domain/$host/$host.$TIMEPOINT.tgz /www/$domain/$host
- done
- done
- find $BACKUP_DIR -type f -mtime +$COPIES -delete