打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Rotational backup with remote backup options

An example rotational backup with remote backup options script.

#!/bin/sh# Rotational Backup with remote backup# Version 1.1# Fire Eater <LinuxRockz@gmail.com># Feburary 4, 2006# Released under the GPL License- http://www.fsf.org/licensing/licenses/gpl.txt###############################################################################SERVER_HOSTNAME="`hostname`"BACKUP_UID="yourbackupuser"BACKUP_GID="yourbackupusersgroup"#ROOT_BACKUP_DIR="/your/backup/directory"CONF_DIR="$ROOT_BACKUP_DIR/etc"#Example: HTTPD, BIND, MYSQLBACKUP_TYPE="HTTPD"######################  Remote Backup   ######################## Use Rsync# You will need to properly set up a key bassed ssh login.USE_RSYNC="n"RSYNC_HOST="yourserver"SSH_RSYNC_USER="yoursshuser"SSH_RSYNC_DEST_DIR="/your/remote/folder/$SERVER_HOSTNAME"## SCP Information and Destination# Your will need to properly set up a key bassed ssh login.USE_SCP="n"SCP_HOST="yourserver"SCP_USER="sshuser"SCP_REMOTEDIR="/your/remote/folder/$SERVER_HOSTNAME"## FTPUSE_FTP="n"#  Syntax for FTP_SERVER:  ftp://user:pass@ftp.server.com/folder  (WITHOUT Trailing /)FTP_SERVER="ftp://"## E-Mail Information and DestinationEMAIL_INFO="n"BACKUP_EMAIL="youremailaddress"##################################  Config Directory/File Check  ##################################if [ ! -d $CONF_DIR ] ; then        mkdir -p $CONF_DIRfiif [ ! -f $CONF_DIR/homedirs ] ; then        echo "No Home Directories List Found"        echo "Please create $CONF_DIR/homedirs"        exitfi######################  Rotational Setup #######################BACKUP_DIR=$ROOT_BACKUP_DIR/$BACKUP_TYPEBACKUP_DEST="$BACKUP_DIR/backup.0"BACKUP="$BACKUP_DIR/backup.0"BACKUP1="$BACKUP_DIR/backup.1"BACKUP2="$BACKUP_DIR/backup.2"BACKUP3="$BACKUP_DIR/backup.3"BACKUP4="$BACKUP_DIR/backup.4"BACKUP5="$BACKUP_DIR/backup.5"BACKUP6="$BACKUP_DIR/backup.6"if [ ! -d $BACKUP_DEST ] ; then        mkdir -p $BACKUP_DESTfiif [ ! -d $BACKUP ] ; then        mkdir $BACKUP_DIR/backup.0fiif [ ! -d $BACKUP1 ] ; then        mkdir $BACKUP_DIR/backup.1fiif [ ! -d $BACKUP2 ] ; then        mkdir $BACKUP_DIR/backup.2fiif [ ! -d $BACKUP3 ] ; then        mkdir $BACKUP_DIR/backup.3fiif [ ! -d $BACKUP4 ] ; then        mkdir $BACKUP_DIR/backup.4fiif [ ! -d $BACKUP5 ] ; then        mkdir $BACKUP_DIR/backup.5fiif [ ! -d $BACKUP6 ] ; then        mkdir $BACKUP_DIR/backup.6fi/bin/rm -rf $BACKUP_DIR/backup.6mv $BACKUP_DIR/backup.5 $BACKUP_DIR/backup.6mv $BACKUP_DIR/backup.4 $BACKUP_DIR/backup.5mv $BACKUP_DIR/backup.3 $BACKUP_DIR/backup.4mv $BACKUP_DIR/backup.2 $BACKUP_DIR/backup.3mv $BACKUP_DIR/backup.1 $BACKUP_DIR/backup.2mv $BACKUP_DIR/backup.0 $BACKUP_DIR/backup.1if [ ! -d $BACKUP ] ; then        mkdir $BACKUP_DIR/backup.0fi####################################     START BACKUP               ###################################START_TIME=`date +%a-%D-@-%X-%Z`###################################HTTP_CONF_DIR="/etc/httpd"USERS_HOME_DIRECTORY="/home"USERS_LIST="$CONF_DIR/homedirs"DATENAME=`date +%Y%m%d`START_TIME=`date +%a-%D-@-%X-%Z`#echo "Backing up HTTPD Conf Directories"tar cfj $BACKUP_DEST/httpd-$DATENAME.tar.bz2 $HTTP_CONF_DIR  >> /dev/null#echo "Backing up Home Directories"#for USER_DIR in `cat $USERS_LIST`;dotar cfj $BACKUP_DEST/$SERVER_HOSTNAME-$USER_DIR--$DATENAME.tar.bz2 $USERS_HOME_DIRECTORY/$USER_DIR  >> /dev/nulldone##Set Permissionschown $BACKUP_UID:$BACKUP_GID $BACKUP_DIR###################################END_TIME=`date +%a-%D-@-%X-%Z`###################################       END BACKUP               ############################################################### Remote Backup Options  ###########################clear#if [ $USE_RSYNC = y ] ; thenecho "Preforming Remote Backup via Rsync"echo ""su -l $BACKUP_UID -c "rsync -az --stats --partial -e ssh $BACKUP_DIR $SSH_RSYNC_USER@$RSYNC_HOST:$SSH_RSYNC_DEST_DIR"  2>&1echo "$BACKUP_TYPE backup has been Rsynced to $RSYNC_HOST"echo ""elseecho "Rsync not turned on"fi#if [ $USE_SCP = y ] ; thenecho "Preforming Remote Backup via SCP"echo ""scp $BACKUP_DEST/$SERVER_HOSTNAME-$USER_DIR--$DATENAME.tar.bz2 $SCP_USER@$SCP_HOST:$SCP_REMOTEDIRecho ""echo "$BACKUP_TYPE Backup has been uploaded via scp to $SCP_HOST"elseecho "SCP not turned on"fi#if [ $USE_FTP = y ] ; thenecho "Preforming Remote Backup vis FTP"echo ""curl -T $BACKUP_DEST/$SERVER_HOSTNAME-$USER_DIR--$DATENAME.tar.bz2 $FTP_SERVER/$SERVER_HOSTNAME-$USER_DIR--$DATENAME.tar.bz2echo "$BACKUP_TYPE  backup has been uploaded via FTP to $FTP_SERVER"elseecho ""echo "FTP not turned on"echo ""fi######################  Backup Results  ######################echo "The current $BACKUP_TYPE backup for $SERVER_HOSTNAME has completed and is located in: $BACKUP_DEST"echo ""echo "Total disk space used for the entire $BACKUP_TYPE backup."echo "Size - Location"echo "`du -hs "$BACKUP_DIR"`"echo ""echo "Total disk space used for the current $BACKUP_TYPE backup."echo "Size - Location"echo "`du -hs "$BACKUP_DEST"`"#####################   Email Results #####################if [ $EMAIL_INFO = y ] ; thenecho "$SERVER_HOSTNAME $BACKUP_TYPE Backup Summary" >> /tmp/emailmsg.txtecho "" >> /tmp/emailmsg.txtecho "Backup Start Time: $START_TIME" >> /tmp/emailmsg.txtecho "Backup End Time: $END_TIME" >> /tmp/emailmsg.txtecho "" >> /tmp/emailmsg.txtecho "Rsync="$USE_RSYNC >> /tmp/emailmsg.txtecho "SCP="$USE_SCP >> /tmp/emailmsg.txtecho "FTP="$USE_FTP >> /tmp/emailmsg.txtecho "" >> /tmp/emailmsg.txtecho "Total disk space used for the entire $BACKUP_TYPE backup." >> /tmp/emailmsg.txtecho "" >> /tmp/emailmsg.txtecho "Size - Location" >> /tmp/emailmsg.txtecho "`du -hs "$BACKUP_DIR"`" >> /tmp/emailmsg.txtecho "" >> /tmp/emailmsg.txtecho "Total disk space used for the current $BACKUP_TYPE backup." >> /tmp/emailmsg.txtecho "" >> /tmp/emailmsg.txtecho "Size - Location" >> /tmp/emailmsg.txtecho "`du -hs "$BACKUP_DEST"`" >> /tmp/emailmsg.txtecho "" >> /tmp/emailmsg.txt#cat /tmp/emailmsg.txt | mail -s"$BACKUP_TYPE Backup Executed for $SERVER_HOSTNAME at $END_TIME" $BACKUP_EMAILrm -f /tmp/emailmsg.txtelseecho "E-Mail not turned on"fiexit
HowTos/Rotational backup with remote backup options (2007-05-17 12:44:37由DanielDeKok编辑)
 
 
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
关于rsync arm 同步
oracle xtts 解决跨平台迁移之一 Recovery Manager (RMAN)
三阶段之二:备份服务(rsync)
使用 rsync 同步(一)
在 Windows 上使用 rsync 同步文件和目录
linux下rsync命令详细整理
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服