- 浏览: 27351 次
- 性别:
- 来自: 北京
文章分类
最新评论
#!/bin/bash
#2009-11-8 第一次编写
#作者:duanyunxi
#版本:v1.1
#备份脚本
##设置备份##
echo "##开始设置备份!##"
if [ -f /etc/crontab ]; then
RETVAL=`service cron status|grep 'running'`
if [ "$RETVAL" != "" ]; then
echo "请选择备份格式(s:数据库|t:tar.gz压缩包)?"
read ENCODE
#################数据库sql脚本备份###########
if [ "$ENCODE" == "s" ] || [ "$ENCODE" == "S" ]; then
##提示输入mysql管理员用户root的密码##
RETVAL="1"
until [ $RETVAL -eq 0 ]
do
echo "请输入mysql管理员用户root的密码"
read MYSQLPASSWD
mysqladmin -uroot -p$MYSQLPASSWD version 1> /dev/null 2>&1
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "mysql管理员root密码输入正确!"
else
echo "mysql管理员密码错误,请重新输入!"
fi
done
##提示输入要备份的数据库名##
echo "请输入要备份数据库名,例如:icfjkcms"
INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
read DATABASE
echo "您输入的数据库名是:$DATABASE,请确认(y|n)?"
read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请输入要备份数据库名,例如:icfjkcms"
else
echo "您输入的备份数据库名为:$DATABASE"
fi
done
##提示输入备份频率##
echo "***定时备份频率格式:分 时 天 月 一周第几天"
echo "***例如:*/20 6-12 * 12 * 表示在12月内,每天的早上6点到12点中,每隔20分钟执行一次"
echo "请输入备份频率,例如:*/2 * * * *"
INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
read RATE
echo "您输入的备份频率是:$RATE,请确认(y|n)?"
read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请输入备份频率,例如:*/2 * * * *"
else
echo "您输入的备份频率为:$RATE"
fi
done
DAY=`date +%Y%m%d`
TIME=`date +%H%M%S`
###备份文件备份脚本存放目录###
mkdir -p /var/backup/$DAY/sh
echo "生成备份的脚本文件"
echo "#!/bin/bash" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.sh
echo "BACKDAY=\`date +%Y%m%d%H%M\`" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.sh
echo "mysqldump --default-character-set=utf8 -hlocalhost -uroot -p$MYSQLPASSWD -B -d --opt -q $DATABASE > /var/backup/$DAY/DDL$DATABASE-\$BACKDAY.sql ;" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.sh
echo "mysqldump --default-character-set=utf8 -hlocalhost -uroot -p$MYSQLPASSWD -B -t --opt -q $DATABASE > /var/backup/$DAY/DML$DATABASE-\$BACKDAY.sql ;" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.sh
chmod 775 /var/backup/$DAY/sh/$DATABASE-SQL$TIME.sh
echo "备份脚本生成完成"
###写README文件
echo "写README文件"
echo "制作人:段云喜" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.readme
echo "制作时间:$DAY" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.readme
echo "$DATABASE-SQL$TIME.sh为备份$DATABASE数据库脚本" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.readme
echo "cron执行$DATABASE-SQL$TIME.sh频率是$RATE" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.readme
echo "备份生成的sql脚本在/var/backup/$DAY目录下" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.readme
echo "备份文件完成,去/var/backup/$DAY/sh/里查看$DATABASE-SQL$TIME.readme文件"
sleep 3
echo "停cron服务"
service cron stop
###定时备份---每隔二分钟备份一次###
echo " $RATE root test -x /var/backup/$DAY/sh/$DATABASE-SQL$TIME.sh && /var/backup/$DAY/sh/$DATABASE-SQL$TIME.sh" >>/etc/crontab
sleep 3
echo "开启cron服务"
service cron start
echo "备份配置完成!"
#################文件夹/文件tar.gz打包备份###########
elif [ "$ENCODE" == "t" ] || [ "$ENCODE" == "T" ]; then
echo "请输入备份文件名前缀,例如:www"
INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
read PREFIX
echo "您输入的备份文件名前缀是:$PREFIX,请确认(y|n)?"
read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请输入备份文件名前缀,例如:www:"
else
echo "您输入的备份文件名前缀为:$PREFIX"
fi
done
echo "请输入要备份的路径,例如:/usr/local/site"
INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
read DATAPATH
echo "您输入要备份的路径是:$DATAPATH,请确认(y|n)?"
read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请输入要备份的路径,例如:/usr/local/site:"
else
echo "你要备份的路径为:$DATAPATH"
fi
done
echo "请输入备份路径中不备份的文件或文件夹:(多个用空格隔开) 如果没有直接确认!"
INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
read FILES
echo "您输入不备份的文件或文件夹是:$FILES,请确认(y|n)?"
read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请输入备份路径中不备份的文件或文件夹:(多个用空格隔开)"
else
echo "您输入不备份的文件或文件夹是:$FILES"
fi
done
##提示输入备份频率##
echo "***定时备份频率格式:分 时 天 月 一周第几天"
echo "***例如:*/20 6-12 * 12 * 表示在12月内,每天的早上6点到12点中,每隔20分钟执行一次"
echo "请输入备份频率,例如:*/2 * * * *"
INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
read RATE
echo "您输入的备份频率是:$RATE,请确认(y|n)?"
read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请输入备份频率,例如:*/2 * * * *"
else
echo "您输入的备份频率为:$RATE"
fi
done
DAY=`date +%Y%m%d`
TIME=`date +%H%M%S`
###备份文件备份脚本存放目录###
mkdir -p /var/backup/$DAY/sh
for FILE in $FILES
do
EXCLUDE="$EXCLUDE --exclude $FILE"
done
echo "生成备份的脚本文件"
echo "#!/bin/bash" >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.sh
echo "BACKDAY=\`date +%Y%m%d%H%M\`" >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.sh
echo "cd $DATAPATH" >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.sh
echo "tar $EXCLUDE -zcpf /var/backup/$DAY/$PREFIX-\$BACKDAY.tar.gz ." >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.sh
chmod 775 /var/backup/$DAY/sh/$PREFIX-TAR$TIME.sh
echo "备份脚本生成完成"
###写README文件
echo "写README文件"
echo "制作人:段云喜" >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.readme
echo "制作时间:$DAY" >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.readme
echo "$PREFIX-TAR$TIME.sh 为备份$DATAPATH的脚本 不包括$FILES" >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.readme
echo "cron执行$PREFIX-TAR$TIME.sh频率是$RATE" >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.readme
echo "备份生成的tar.gz压缩包在/var/backup/$DAY目录下" >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.readme
echo "备份文件完成,去/var/backup/$DAY/sh/里查看$PREFIX-TAR$TIME.readme文件"
sleep 3
echo "停此cron服务"
service cron stop
###定时备份---每隔二分钟备份一次###
echo " $RATE root test -x /var/backup/$DAY/sh/$PREFIX-TAR$TIME.sh && /var/backup/$DAY/sh/$PREFIX-TAR$TIME.sh" >>/etc/crontab
sleep 3
echo "开启cron服务"
service cron start
echo "备份配置完成!"
fi
fi
fi
#2009-11-8 第一次编写
#作者:duanyunxi
#版本:v1.1
#备份脚本
##设置备份##
echo "##开始设置备份!##"
if [ -f /etc/crontab ]; then
RETVAL=`service cron status|grep 'running'`
if [ "$RETVAL" != "" ]; then
echo "请选择备份格式(s:数据库|t:tar.gz压缩包)?"
read ENCODE
#################数据库sql脚本备份###########
if [ "$ENCODE" == "s" ] || [ "$ENCODE" == "S" ]; then
##提示输入mysql管理员用户root的密码##
RETVAL="1"
until [ $RETVAL -eq 0 ]
do
echo "请输入mysql管理员用户root的密码"
read MYSQLPASSWD
mysqladmin -uroot -p$MYSQLPASSWD version 1> /dev/null 2>&1
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "mysql管理员root密码输入正确!"
else
echo "mysql管理员密码错误,请重新输入!"
fi
done
##提示输入要备份的数据库名##
echo "请输入要备份数据库名,例如:icfjkcms"
INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
read DATABASE
echo "您输入的数据库名是:$DATABASE,请确认(y|n)?"
read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请输入要备份数据库名,例如:icfjkcms"
else
echo "您输入的备份数据库名为:$DATABASE"
fi
done
##提示输入备份频率##
echo "***定时备份频率格式:分 时 天 月 一周第几天"
echo "***例如:*/20 6-12 * 12 * 表示在12月内,每天的早上6点到12点中,每隔20分钟执行一次"
echo "请输入备份频率,例如:*/2 * * * *"
INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
read RATE
echo "您输入的备份频率是:$RATE,请确认(y|n)?"
read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请输入备份频率,例如:*/2 * * * *"
else
echo "您输入的备份频率为:$RATE"
fi
done
DAY=`date +%Y%m%d`
TIME=`date +%H%M%S`
###备份文件备份脚本存放目录###
mkdir -p /var/backup/$DAY/sh
echo "生成备份的脚本文件"
echo "#!/bin/bash" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.sh
echo "BACKDAY=\`date +%Y%m%d%H%M\`" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.sh
echo "mysqldump --default-character-set=utf8 -hlocalhost -uroot -p$MYSQLPASSWD -B -d --opt -q $DATABASE > /var/backup/$DAY/DDL$DATABASE-\$BACKDAY.sql ;" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.sh
echo "mysqldump --default-character-set=utf8 -hlocalhost -uroot -p$MYSQLPASSWD -B -t --opt -q $DATABASE > /var/backup/$DAY/DML$DATABASE-\$BACKDAY.sql ;" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.sh
chmod 775 /var/backup/$DAY/sh/$DATABASE-SQL$TIME.sh
echo "备份脚本生成完成"
###写README文件
echo "写README文件"
echo "制作人:段云喜" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.readme
echo "制作时间:$DAY" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.readme
echo "$DATABASE-SQL$TIME.sh为备份$DATABASE数据库脚本" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.readme
echo "cron执行$DATABASE-SQL$TIME.sh频率是$RATE" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.readme
echo "备份生成的sql脚本在/var/backup/$DAY目录下" >> /var/backup/$DAY/sh/$DATABASE-SQL$TIME.readme
echo "备份文件完成,去/var/backup/$DAY/sh/里查看$DATABASE-SQL$TIME.readme文件"
sleep 3
echo "停cron服务"
service cron stop
###定时备份---每隔二分钟备份一次###
echo " $RATE root test -x /var/backup/$DAY/sh/$DATABASE-SQL$TIME.sh && /var/backup/$DAY/sh/$DATABASE-SQL$TIME.sh" >>/etc/crontab
sleep 3
echo "开启cron服务"
service cron start
echo "备份配置完成!"
#################文件夹/文件tar.gz打包备份###########
elif [ "$ENCODE" == "t" ] || [ "$ENCODE" == "T" ]; then
echo "请输入备份文件名前缀,例如:www"
INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
read PREFIX
echo "您输入的备份文件名前缀是:$PREFIX,请确认(y|n)?"
read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请输入备份文件名前缀,例如:www:"
else
echo "您输入的备份文件名前缀为:$PREFIX"
fi
done
echo "请输入要备份的路径,例如:/usr/local/site"
INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
read DATAPATH
echo "您输入要备份的路径是:$DATAPATH,请确认(y|n)?"
read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请输入要备份的路径,例如:/usr/local/site:"
else
echo "你要备份的路径为:$DATAPATH"
fi
done
echo "请输入备份路径中不备份的文件或文件夹:(多个用空格隔开) 如果没有直接确认!"
INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
read FILES
echo "您输入不备份的文件或文件夹是:$FILES,请确认(y|n)?"
read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请输入备份路径中不备份的文件或文件夹:(多个用空格隔开)"
else
echo "您输入不备份的文件或文件夹是:$FILES"
fi
done
##提示输入备份频率##
echo "***定时备份频率格式:分 时 天 月 一周第几天"
echo "***例如:*/20 6-12 * 12 * 表示在12月内,每天的早上6点到12点中,每隔20分钟执行一次"
echo "请输入备份频率,例如:*/2 * * * *"
INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
read RATE
echo "您输入的备份频率是:$RATE,请确认(y|n)?"
read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请输入备份频率,例如:*/2 * * * *"
else
echo "您输入的备份频率为:$RATE"
fi
done
DAY=`date +%Y%m%d`
TIME=`date +%H%M%S`
###备份文件备份脚本存放目录###
mkdir -p /var/backup/$DAY/sh
for FILE in $FILES
do
EXCLUDE="$EXCLUDE --exclude $FILE"
done
echo "生成备份的脚本文件"
echo "#!/bin/bash" >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.sh
echo "BACKDAY=\`date +%Y%m%d%H%M\`" >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.sh
echo "cd $DATAPATH" >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.sh
echo "tar $EXCLUDE -zcpf /var/backup/$DAY/$PREFIX-\$BACKDAY.tar.gz ." >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.sh
chmod 775 /var/backup/$DAY/sh/$PREFIX-TAR$TIME.sh
echo "备份脚本生成完成"
###写README文件
echo "写README文件"
echo "制作人:段云喜" >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.readme
echo "制作时间:$DAY" >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.readme
echo "$PREFIX-TAR$TIME.sh 为备份$DATAPATH的脚本 不包括$FILES" >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.readme
echo "cron执行$PREFIX-TAR$TIME.sh频率是$RATE" >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.readme
echo "备份生成的tar.gz压缩包在/var/backup/$DAY目录下" >> /var/backup/$DAY/sh/$PREFIX-TAR$TIME.readme
echo "备份文件完成,去/var/backup/$DAY/sh/里查看$PREFIX-TAR$TIME.readme文件"
sleep 3
echo "停此cron服务"
service cron stop
###定时备份---每隔二分钟备份一次###
echo " $RATE root test -x /var/backup/$DAY/sh/$PREFIX-TAR$TIME.sh && /var/backup/$DAY/sh/$PREFIX-TAR$TIME.sh" >>/etc/crontab
sleep 3
echo "开启cron服务"
service cron start
echo "备份配置完成!"
fi
fi
fi
发表评论
-
linux密码破解
2011-02-14 10:39 1229opsensuse-linux密码破解( ... -
名人博客
2011-01-05 15:28 650http://www.ha97.com/ http://don ... -
linux单网卡绑定多ip
2010-12-13 15:09 1466Linux给一个网卡绑定多个IP方法 1.Redhat系列( ... -
jdk+mysql+nginx+resin一步安装脚本
2010-11-09 17:43 1546#!/bin/bash #作者:duanyunxi #版本:v ... -
crontab详解
2010-11-08 15:46 827crontab日志记录:/var/spool/mail/roo ... -
open-suse网络配置
2010-10-22 15:27 14911.ip配置 修改/etc/sysconfig/network ... -
Shell基本语法
2010-07-08 16:09 889一、Shell语法 1.1、变量 ...
相关推荐
本文标题为「SUSE Linux 定时备份脚本」,表明了本文的主要内容是关于在 SUSE Linux 系统上创建一个定时备份脚本来自动备份应用程序及数据库。 描述解释 本文描述中提到的是将应用程序及数据库从一台服务器备份到...
SUSE-Linux下配置PXE自动安装SUSE-Linux系统。Linux下DNS服务器的配置。
suse-linux-64-GM-DVD1.iso 安装文件下载
标题“suse-linux-11-64.rar_suse”暗示了这是一个与SUSE Linux Enterprise Server 11 64位版本相关的压缩文件,通常包含安装指南、配置文档或者更新信息。SUSE Linux是一款来自德国的开源操作系统,以其稳定性、...
SUSE-Linux基础培训,常见命令,LINUX文件系统,用户和组配置文件,进程基础,网络配置,文件打包和压缩,用户登陆监控
SUSE-linuxFTP及TELNET配置.pdf
QT的Oracle驱动插件QOCI-for SuSE-Linux 用法说明请参考: http://blog.csdn.net/fm0517/archive/2010/05/21/5613289.aspx
MongoDB Community Server(mongodb-shell-linux-x86_64-suse12-5.0.4.tgz)适用于SUSE12 MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。 MongoDB是...
根据提供的文件信息,我们可以推断出这是一款名为"SUSE-12-SP2-Server-DVD-x86_64-GM-DVD1.iso"的操作系统镜像文件,该文件与SUSE Linux操作系统有关。接下来将详细介绍与该文件相关的知识点。 ### SUSE Linux简介 ...
MongoDB Community Server(mongodb-shell-linux-x86_64-suse15-5.0.4.tgz)适用于SUSE15 MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。 MongoDB是...
SUSE Linux Enterprise 12 SP2 X86_64 (Server and desktop) 总共4个ISO,Desktop和Server各两个iso文件,一共20多G。
Suse Linux 11 双机集群配置是一项重要的任务,主要用于确保关键服务的高可用性和负载均衡。以下将详细阐述配置过程,包括安装前的准备工作、Heartbeat 的安装与配置、以及同步服务的设定。 **一、安装前准备** 在...
Suselinux 系统备份恢复配置收集是指在 Suselinux 操作系统中对系统进行备份和恢复的配置收集,旨在确保系统的安全和可靠性。下面是 Suselinux 系统备份恢复配置收集的详细说明: 一、安装 rear 软件包 Rear ...
学习suse linux,是系统管理员的学习资料,比较完整的介绍了suse的使用方法
在这个压缩包中,"mongodb-linux-x86_64-suse11-3.0.4" 文件包含了运行MongoDB 3.0.4所需的所有二进制文件和库,用户可以直接在SUSE 11系统上安装和运行。安装过程通常包括解压文件、配置`mongod.conf`设置文件,...
【SUSE Linux 11 安装详细指南】 SUSE Linux 11 是一款功能强大的企业级操作系统,其安装过程需要...SUSE Linux 11以其稳定性、安全性和易用性深受企业用户欢迎,正确安装后,可以提供高效稳定的服务器和工作站环境。
1. **解压文件**:使用`tar -zxvf mongodb-linux-x86_64-rhel70-3.6.4.tgz`命令解压缩文件。 2. **创建数据目录**:为MongoDB创建一个数据存储目录,例如`/data/db`,并确保其具有合适的权限。 3. **配置环境变量*...
在SUSE Linux(如openSUSE)中,为了实现系统启动时自动执行某些脚本或命令,需要了解和利用特定的启动脚本机制。本文将详细介绍openSUSE 11和10 SP2中的启动文件设置方法,并通过一个具体的例子来展示如何实现开机...
SUSE LINUX系统备份恢复配置是指在SUSE LINUX系统中进行备份和恢复配置的过程,旨在保护系统的数据和配置,以防止数据丢失和系统崩溃。 首先,需要安装rear软件包,rear是SUSE LINUX系统中的备份和恢复工具,版本号...