>

Linux咋办批管理自动保存几天的备份呢,数据导出

- 编辑:www.bifa688.com -

Linux咋办批管理自动保存几天的备份呢,数据导出

LINUX下的自行备份对数据的平安很主要,当什么做到自动备份,之保留近日几天的多少吧?上面以哥们分类生活网www.yes81.net为例子来举办测验,网址的论坛我们上传提交的附属类小部件、汉子生活网址的主系统上传的附件以及数据库是必需开展备份的一个第一数据。

L007-oldboy-mysql-dba-lesson07

sqloader 数据导出怎么写。
在数据库中有79张表 将其全体导出为txt格式的文本 该怎么贯彻
导入语句如下:#!/bin/sh
start_time=date "%Y-%m-%d %H:%M:%S"
start=date %s

  该服务器采纳阵列双硬盘,由此硬盘崩溃错过数据是不忧郁的,首就算放心不下因系统出现难题也许误操作形成的数码错失。

 

#set -x
user=fina
password=fina
base_dir=/home/oracle/eastloader
ctl_dir=${base_dir}/ctl_dir
log_dir=${base_dir}/log

  1、硬盘分区backdata是特意用作备份使用的

 

###########################################################
##get data_date,default the last day of last month##
if [ $# -ne 1 ];then
data_date=date %Y%m%d
yy=echo ${data_date}|cut -c 1-4
mm=echo ${data_date}|cut -c 5-6
dd=echo ${data_date}|cut -c 7-8
if [ ${mm} -ne 1 ];then
mm=expr ${mm} - 1
aa=cal ${mm} ${yy}
dd=echo ${aa}|awk '{print $NF}'
if [ ${mm} -lt 10 ];then
data_date=${yy}0${mm}${dd}
else
data_date=${yy}${mm}${dd}
fi
else
yy=expr ${yy} - 1
mm=12
bb=31
data_date=${yy}${mm}${bb}
fi
else
data_date=${1}
fi

  2、mydata是数额分区,mysql是数据库文件目录;bbs 是论坛的文件目录;yes81是主站yes81.net的文件目录

 

##create ctl files##

  以后我们的靶子是做到每日活动备份,并且只保留10天的数码,10天前的数额自动删除

 

if [ -d ${base_dir}/ctl_dir/${data_date} ];then
rm -rf ${base_dir}/ctl_dir/${data_date}
fi
##create ctl files##

  为此大家编辑了上边的自动备份的批管理公事,而且在crontab排程里面扩充了每天午夜3点自行施行的天职。

 

if [ -d ${base_dir}/ctl_dir/${data_date} ];then
rm -rf ${base_dir}/ctl_dir/${data_date}
fi

  -----------------bacpupdata.bat-------------------------------------

 

if [ ! -d ${base_dir}/ctl_dir/${data_date} ];then
mkdir -p ${base_dir}/ctl_dir/${data_date}
fi

  cd /backdata

[root@web01 ~]# mysqldump -uroot -ptestpassword -A >/root/mysql_backup/testbackup20141026.sql  #全库备份

#cp ${base_dir}/ctl_dir/${data_date}/* ${base_dir}/ctl_dir/stand/
cd ${base_dir}/ctl_dir/${data_date}
#chmod 755 *

  #----删除10天前的备份

 

cat ${base_dir}/config.ini | while read line
do
touch B1068H215030001-${line}-${data_date}.ctl
chmod 755 ${base_dir}/ctl_dir/${data_date}/B1068H215030001-${line}-${data_date}.ctl
echo "load data CHARACTERSET ZHS16GBK">>${base_dir}/ctl_dir/${data_date}/B1068H215030001-${line}-${data_date}.ctl
echo "infile '${base_dir}/data_dir/${data_date}/B1068H215030001-${line}-${data_date}.txt'">>${base_dir}/ctl_dir/${data_date}/B1068H215030001-${line}-${data_date}.ctl
cat ${base_dir}/ctl_dir/stand/${line}.ctl >>${base_dir}/ctl_dir/${data_date}/B1068H215030001-${line}-${data_date}.ctl
done

  date -d -15-day %Y-%m-%d > dd.txt

[root@web01 ~]# mysqladmin -uroot -ptestpassword shutdown    #关库

###########################################################
##main sqlloader##
if [ -d ${base_dir}/log/${data_date} ];then
rm -rf ${base_dir}/log/${data_date}
fi

  read dateold < dd.txt

[root@web01 ~]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/var/lib/mysql/my.cnf &    #启动

if [ ! -d ${base_dir}/log/${data_date} ];then
mkdir -p ${base_dir}/log/${data_date}
fi

  rm dd.txt -f

 

if [ -f ${base_dir}/${data_date}_load_main.log ];then
rm -rf ${base_dir}/${data_date}_load_main.log
fi

  rm -rf $dateold

[root@web01 ~]# mysql  -ptestpassword < /root/mysql_backup/testbackup20141026.sql     #恢复

cd ${base_dir}

  date -d -14-day %Y-%m-%d > dd.txt

 

cat ${base_dir}/config.ini | while read line
do
echo "${base_dir}/data_dir/${data_date}/B1068H215030001-${line}-${data_date}.txt"
if [ -f ${base_dir}/data_dir/${data_date}/B1068H215030001-${line}-${data_date}.txt ];then
sqlldr userid=${user}/${password} direct=true control=${base_dir}/ctl_dir/${data_date}/B1068H215030001-${line}-${data_date}.ctl log=${base_dir}/log/${data_date}/B1068H215030001-${line}-${data_date}.log rows=100000 readsize=25800000 bindsize=25800000

  read dateold < dd.txt

[root@web01 ~]# mysqldump -uroot -ptestpassword mydb> /root/mysql_backup/mydb_20141026.sql  #备份单个库

echo "<<<<<<<<<<<<<<<<<<<<date %Y%m%d-%H:%M:%S start to load ${line}">>${data_date}_load_main.log
cat ${base_dir}/log/${data_date}/B1068H215030001-${line}-${data_date}.log|grep "Total logical records skipped">>${data_date}_load_main.log
cat ${base_dir}/log/${data_date}/B1068H215030001-${line}-${data_date}.log|grep "Total logical records read">>${data_date}_load_main.log
cat ${base_dir}/log/${data_date}/B1068H215030001-${line}-${data_date}.log|grep "Total logical records rejected">>${data_date}_load_main.log
cat ${base_dir}/log/${data_date}/B1068H215030001-${line}-${data_date}.log|grep "Total logical records discarded">>${data_date}_load_main.log
else
echo ">>>>>>>>>>>>>>>THE DATA FILE IS NOT READY!! ${line}">>${data_date}_load_main.log
fi
done

  rm dd.txt -f

[root@web01 ~]# mysql -uroot -ptestpassword mydb < /root/mysql_backup/mydb_20141026.sql       #还原单个库

end_time=date "%Y-%m-%d %H:%M:%S"
end=date %s
echo "中间表数据结转成功,时间一齐:"expr $end - $start

  rm -rf $dateold

 

导出语句小编该怎么去写

  date -d -13-day %Y-%m-%d > dd.txt

[root@web01 ~]# vi abc.sh    #分表备份脚本

  read dateold < dd.txt

#!/bin/bash

  rm dd.txt -f

#author:DBA

  rm -rf $dateold

#2016-06-12

  date -d -12-day %Y-%m-%d > dd.txt

#modify by DBA 2016-06-12

  read dateold < dd.txt

 

  rm dd.txt -f

dbname="mydb"

  rm -rf $dateold

dpath="/mysql_backup/$dbname"

  date -d -11-day %Y-%m-%d > dd.txt

myday=`date %Y%m%d`

  read dateold < dd.txt

 

  rm dd.txt -f

if [ ! -d "$dpath" ]

  rm -rf $dateold

then

  date -d -10-day %Y-%m-%d > dd.txt

mkdir -p $dpath

  read dateold < dd.txt

fi

  rm dd.txt -f

 

  rm -rf $dateold

mysql -uroot -ptestpassword -e "use $dbname;show tables;"|grep -v Tables_in_ > $dpath/table_list.txt

  #-----新创建当天的文书备份

 

  date -d 0-day %Y-%m-%d > dd.txt

while read line

  read date1 < dd.txt

do

  rm dd.txt -f

mysqldump -uroot -ptestpassword $dbname ${line} > /$dpath/${line}_$myday.sql

  mkdir $date1

done <$dpath/table_list.txt

  rar a /backdata/$date1/database$date1.rar /mydata/mysql

 

  rar a /backdata/$date1/bbs$date1.rar /mydata/bbs/WEB-INF/lybbs/upload

rm -rf $dpath/table_list.txt

  rar a /backdata/$date1/buyi$date1.rar /mydata/yes81

 

  本贴的版权属于

 

...

 

 

www.bifa688.com 1

 

[root@web01 ~]# vi backup.sh

#!/bin/bash

 

dpath="/mysql_backup"

mydays="7"

username="root"

mysql_pwd="testpassword"

xmysql="/usr/local/mysql/bin/mysql -S /tmp/mysql.sock -u$username -p${mysql_pwd}"

xmysqldump="/usr/local/mysql/bin/mysqldump -S /tmp/mysql.sock -u$username -p${mysql_pwd}"

today=`date %Y%m%d`

old_backup_dir=`date -d "-${mydays} day" %Y%m%d`

 

if [ -d $old_backup_dir ];then

  rm -rf $old_backup_dir

fi

 

if [ ! -d $today  ]; then

  mkdir -p $dpath/$today

  cp /var/lib/mysql/my.cnf $dpath/$today

fi

 

 

$xmysql -e "show databases;"|grep -vE "(Database|_schema)" > $dpath/db_list

$xmysql -e "flush tables with read lock;"

 

while read dbname

do

 

  if [ ! -d $dpath/$today/$dbname ];then

    mkdir -p $dpath/$today/$dbname

  fi

 

#######################

  #echo $dbname

  $xmysql -e "use $dbname; show tables;"|grep -vE "(Tables_in|general_log|slow_log)" > $dpath/table_list

 

  while read tablename

  do

    #echo "echo $tablename"

    $xmysqldump $dbname $tablename -R --events --triggers > $dpath/$today/$dbname/$tablename.sql

    done < $dpath/table_list

#######################

done < $dpath/db_list

 

rm -rf $dpath/db_list

rm -rf $dpath/table_list

 

ls -al /application/mysql/data/mysql-bin* | grep -v mysql-bin.index  | tail -1 | awk '{print $5,$9}'| awk -F'/' '{print $1,$5}' > /mysql_backup/$today/position.txt

 

$xmysql -e "unlock tables;"

 

 

 

www.bifa688.com 2

 

 [root@web01 ~]# vi backup2.sh  

#!/bin/bash

dpath="/mysql_backup2"

 

if [ ! -d $dpath ]; then

  mkdir -p $dpath

fi

 

today=`date %Y-%m-%d`

before_day="$today 00:00:00"

 

mysql -S /tmp/mysql.sock -uroot -ptestpassword -e "PURGE MASTER LOGS BEFORE '$before_day'"

 

 

n=`ps waux | grep mysql |grep -v grep | awk '{print $2}' | wc -l`

 

if [ $n -gt 0 ]www.bifa688.com,;then

  /usr/local/mysql/bin/mysqladmin -S /tmp/mysql.sock -u root -ptestpassword shutdown

fi

 

tar czf /mysql_backup2/mysql_`date %w`.tar.gz /var/lib/mysql

 

/usr/local/mysql/bin/mysqld_safe --defaults-file=/var/lib/mysql/my.cnf &

 

m=`ps waux | grep mysql |grep -v grep | awk '{print $2}' | wc -l`

 

if [ $m -ge 2 ];then

  echo "start fail"

fi

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

发源为知笔记(Wiz)

本文由bifa688.com发布,转载请注明来源:Linux咋办批管理自动保存几天的备份呢,数据导出