码迷,mamicode.com
首页 > 其他好文 > 详细

最近为公司制定的备份解决方案

时间:2017-04-20 17:40:34      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:samba   backup   tar   nsf   

说明

不用TSM,不用CA,不用带库,不用NBU

对于差钱的公司来说,拿土方法自己弄了套免费的

1、拓扑

技术分享

2、排程技术分享

3、各服务器配置说明

备份服务器设置:

1、nfs搭建
[root@wubackup oraclebackup]# rpm -qa | grep nfs
nfs4-acl-tools-0.3.3-6.el6.x86_64
nfs-utils-1.2.3-39.el6.x86_64
nfs-utils-lib-1.1.5-6.el6.x86_64
[root@wubackup home]# vim /etc/exports 
home/oraclebackup 10.55.1.204(rw,no_root_squash)
home/eipbackup 10.55.1.3(rw,no_root_squash)
home/wuwis2backup 10.55.1.88(rw,no_root_squash)
home/wuwis1backup 10.55.1.10(rw,no_root_squash)
home/wulmailbackup 10.55.1.13(rw,no_root_squash)
home/wuwtl1backup 10.55.1.14(rw,no_root_squash)
[root@wubackup home]# exportfs -r
[root@wubackup home]# service start nfs.service
start: unrecognized service
[root@wubackup home]# service nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]
[root@wubackup home]# ss -tnl
State      Recv-Q Send-Q             Local Address:Port               Peer Address:Port 
LISTEN     0      128                            *:875                           *:*     
LISTEN     0      128                           :::43660                        :::*     
LISTEN     0      64                            :::34191                        :::*     
LISTEN     0      128                           :::58255                        :::*     
LISTEN     0      128                           :::111                          :::*     
LISTEN     0      128                            *:111                           *:*     
LISTEN     0      128                           :::41842                        :::*     
LISTEN     0      128                            *:35668                         *:*     
LISTEN     0      128                           :::22                           :::*     
LISTEN     0      128                            *:22                            *:*     
LISTEN     0      128                    127.0.0.1:631                           *:*     
LISTEN     0      128                          ::1:631                          :::*     
LISTEN     0      64                             *:48665                         *:*     
LISTEN     0      100                          ::1:25                           :::*     
LISTEN     0      100                    127.0.0.1:25                            *:*     
LISTEN     0      128                           :::56346                        :::*     
LISTEN     0      128                    127.0.0.1:6010                          *:*     
LISTEN     0      128                          ::1:6010                         :::*     
LISTEN     0      128                    127.0.0.1:6011                          *:*     
LISTEN     0      128                          ::1:6011                         :::*     
LISTEN     0      128                            *:36064                         *:*     
LISTEN     0      64                            :::2049                         :::*     
LISTEN     0      64                             *:2049                          *:*     
LISTEN     0      128                            *:54337                         *:*     
LISTEN     0      128                            *:49322                         *:*     
[root@wubackup home]# ss -tnl | grep 2049
LISTEN     0      64                       :::2049                    :::*     
LISTEN     0      64                        *:2049                     *:*  
[root@wubackup home]# ls
eipbackup  lost+found  oraclebackup  wulmailbackup   wuwis1backup   wuwis2backup  wuwtl1backup

2、samba服务搭建
说明:本来规划的时候都是使用nfs提供服务,但是server 2003要挂载nfs文件夹需要使用sfu插件,实在国内找不到资源,再次吐槽下天朝。所以改用了使用samba提供服务。
[root@wubackup oraclebackup]# yum install samba -y
Installed:
  samba.x86_64 0:3.6.23-42.el6_9                                                                                   

Dependency Updated:
  libsmbclient.x86_64 0:3.6.23-42.el6_9                        samba-client.x86_64 0:3.6.23-42.el6_9               
  samba-common.x86_64 0:3.6.23-42.el6_9                        samba-winbind.x86_64 0:3.6.23-42.el6_9              
  samba-winbind-clients.x86_64 0:3.6.23-42.el6_9              

Complete!
[root@wubackup oraclebackup]# service smb status
smbd is stopped
[root@wubackup oraclebackup]# useradd wuwis1
[root@wubackup oraclebackup]# useradd wuwis2
[root@wubackup oraclebackup]# smbpasswd -a wuwis1
New SMB password:
Retype new SMB password:
Added user wuwis1.
[root@wubackup oraclebackup]# smbpasswd -a wuwis2
New SMB password:
Retype new SMB password:
Added user wuwis2.
[root@wubackup oraclebackup]# vim /etc/samba/smb.conf 
[root@wubackup oraclebackup]# cd /etc/samba/
[root@wubackup samba]# ls
lmhosts  smb.conf  smbusers
[root@wubackup samba]# cp smb.conf{,.bak}
[root@wubackup samba]# ls
lmhosts  smb.conf  smb.conf.bak  smbusers
[root@wubackup samba]# vim smb.conf
[wuwis1backup]     
    comment = wuwis1backup
    path= /home/wuwis1backup     
    public = yes     
    valid users = wuwis1     
    read list = wuwis1   
    write list = wuwis1 

[wuwis2backup]
    comment = wuwis2backup
    path= /home/wuwis2backup
    public = yes
    valid users = wuwis2
    read list = wuwis2
    write list = wuwis2
[root@wubackup samba]# service smb start
Starting SMB services:                                     [  OK  ]

3、脚本说明:
[root@wubackup ~]# crontab -l
#tar backupfile
12 8 * * * /OPS/tar.sh &>>/OPS/crontar.log

#rm old backupfile
0 17 * * * /OPS/rmoldbak.sh &>>/OPS/cronrm.log

[root@wubackup ~]# cat /OPS/tar.sh 
#!/bin/bash
#tar backup file

#tar eip backupfile
eipbackupfile=/home/eipbackup/eipbak`date -d "1 days ago" +%y%m%d`
if [ -e $eipbackupfile ];then
    echo "`date`" >> /OPS/eiptar.log
    echo "tar eipbackupfile start" >>/OPS/eiptar.log
    tar -zcf $eipbackupfile.tar.gz $eipbackupfile
    rm -rf $eipbackupfile
    echo "`date`" >> /OPS/eiptar.log
        echo "tar eipbackupfile sucsessful" >>/OPS/eiptar.log
else
    echo "`date`" >> /OPS/eiptar.log
        echo "tar eipbackupfile fail,file not exist!" >>/OPS/eiptar.log

fi

#tar wuwtl1 backupfile
wuwtl1backupfile=/home/wuwtl1backup/wuwtl1bak`date +%y%m%d`
if [ -e $wuwtl1backupfile ];then
        echo "`date`" >> /OPS/wuwtl1tar.log
        echo "tar wuwtl1backupfile start" >>/OPS/wuwtl1tar.log
        tar -zcf $wuwtl1backupfile.tar.gz $wuwtl1backupfile
        rm -rf $wuwtl1backupfile
        echo "`date`" >> /OPS/wuwtl1tar.log
        echo "tar wuwtl1backupfile sucsessful" >>/OPS/wuwtl1tar.log
else
        echo "`date`" >> /OPS/wuwtl1tar.log
        echo "tar wuwtl1backupfile fail,file not exist!" >>/OPS/wuwtl1tar.log

fi

#tar wuwis2 backupfile
wuwis2backupfile=/home/wuwis2backup/wuwis2bak`date +%y%m%d`
if [ -e $wuwis2backupfile ];then
        echo "`date`" >> /OPS/wuwis2tar.log
        echo "tar wuwis2backupfile start" >>/OPS/wuwis2tar.log
        tar -zcf $wuwis2backupfile.tar.gz $wuwis2backupfile
        rm -rf $wuwis2backupfile
        echo "`date`" >> /OPS/wuwis2tar.log
        echo "tar wuwis2backupfile sucsessful" >>/OPS/wuwis2tar.log
else
        echo "`date`" >> /OPS/wuwis2tar.log
        echo "tar wuwis2backupfile fail,file not exist!" >>/OPS/wuwis2tar.log

fi

#tar wuwis1 backupfile
wuwis1backupfile=/home/wuwis1backup/wuwis1bak`date +%y%m%d`
if [ -e $wuwis1backupfile ];then
        echo "`date`" >> /OPS/wuwis1tar.log
        echo "tar wuwis1backupfile start" >>/OPS/wuwis1tar.log
        tar -zcf $wuwis1backupfile.tar.gz $wuwis1backupfile
        rm -rf $wuwis1backupfile
        echo "`date`" >> /OPS/wuwis1tar.log
        echo "tar wuwis1backupfile sucsessful" >>/OPS/wuwis1tar.log
else
        echo "`date`" >> /OPS/wuwis1tar.log
        echo "tar wuwis1backupfile fail,file not exist!" >>/OPS/wuwis1tar.log
fi

[root@wubackup ~]# cat /OPS/rmoldbak.sh 
#!/bin/bash
#rm old backupfile

#rm oraclebackup
#oracle backup keep 7 days 
echo `date` >>/OPS/rmorabak.log
echo "rm old oraclebackup start" >>/OPS/rmorabak.log
find /home/oraclebackup/ -ctime +6 | xargs rm -rf
echo "old oraclebackup rm finish sucessful" >>/OPS/rmorabak.log

#rm wuwtl1backup
#wuwtl1 backup keep 7 days
echo `date` >>/OPS/rmwuwtl1bak.log
echo "rm old wuwtl1backup start" >>/OPS/rmwuwtl1bak.log
find /home/wuwtl1backup/ -ctime +6 | xargs rm -rf
echo "old wuwtl1backup rm finish sucessful" >>/OPS/rmwuwtl1bak.log

#rm wulmailbackup
#wulmail backup keep 5 days
echo `date` >>/OPS/rmwulmailbak.log
echo "rm old wulmailbackup start" >>/OPS/rmwulmailbak.log
find /home/wulmailbackup/ -ctime +4 | xargs rm -rf
echo "old wulmailbackup rm finish sucessful" >>/OPS/rmwulmailbak.log

#rm eipbackup
#eip backup keep 5 days
echo `date` >>/OPS/rmeipbak.log
echo "rm old eipbackup start" >>/OPS/rmeipbak.log
find /home/eipbackup/ -ctime +4 | xargs rm -rf
echo "old eipbackup rm finish sucessful" >>/OPS/rmeipbak.log

#rm wuwis2backup
#wuwis2 backup keep 5 days
echo `date` >>/OPS/rmwuwis2bak.log
echo "rm old wuwis2 backup start" >>/OPS/rmwuwis2bak.log
find /home/wuwis2backup/ -ctime +4 | xargs rm -rf
echo "old wuwis2backup rm finish sucessful" >>/OPS/rmwuwis2bak.log

#rm wuwis1backup
#wuwis1 backup keep 5 days
echo `date` >>/OPS/rmwuwis1bak.log
echo "rm old wuwis1 backup start" >>/OPS/rmwuwis1bak.log
find /home/wuwis1backup/ -ctime +4 | xargs rm -rf
echo "old wuwis1backup rm finish sucessful" >>/OPS/rmwuwis1bak.log

oracle db

1、进行nfs挂载,并加入fstab中
[root@DataGuard script]# showmount -e 10.55.2.83
Export list for 10.55.2.83:
/home/oraclebackup 10.55.1.204
[root@DataGuard script]# cd /
[root@DataGuard /]# mkdir oraclebackup
[root@DataGuard /]# mount -t nfs 10.55.2.83:/home/oraclebackup /oraclebackup

fstab中添加
10.55.2.83:/home/oraclebackup   /oraclebackup   nfs defaults    0 0

2、设定脚本,添加crontab中
#dbbackup to wubackup
30 9 * * * /OPS/orabackup.sh

3、脚本说明:
#!/bin/bash
# tar oraclebackup file  

# check RMAN is run?
filename="/mnt/rman/log/RmanBackup_`date +%y%m%d`.log"
comparedata="Recovery Manager complete."

if [ -e $filename ];then
    echo "`date` RMAN is run" &>> /OPS/tarlog
else
    echo "`date` RMAN is not run,please check" &>> /OPS/tarlog
    exit 1
fi

# check RMAN is OK?
data=`tail -1 $filename`
if [ "$data" == "$comparedata" ];then
    echo "`date` Rman backup sucess" &>> /OPS/tarlog
else
    echo "`date` Rman backup fail" &>> /OPS/tarlog
    exit 2
fi

# tar backupfile and move to backupserver
/usr/bin/find /mnt/rman -name ‘oradb1*‘ > /OPS/tarlist
for i in `/bin/cat /OPS/tarlist`;do
    echo "`date` tar $i start" &>> /OPS/tarlog
    tar -zcvf $i.tar.gz $i &>> /OPS/tarlog 
done

if [ $? -eq 0 ];then
    echo "`date` tar end success" &>> /OPS/tarlog
    mv /mnt/rman/*.tar.gz /oraclebackup
    if [ $? -eq 0 ];then
        echo "`date` move to oraclebackup end success" &>> /OPS/tarlog
    else
        echo "`date` move to oraclebackup fail" &>> /OPS/tarlog
    fi

else
    echo "`date` tar fail" &>> /OPS/tarlog
fi

mail

1、nfs挂载,fstab中添加
10.55.2.83:/home/wulmailbackup   /wulmailbackup   nfs     defaults        0 0

2、脚本编写并在crontab中添加
#wulmail backup to wubackup
0 21 * * * /OPS/wulmailbackup.sh

3、脚本说明:
#!/bin/bash
#wulmail data backup

logfile=/OPS/wulmailbackup.log
bakfile=wulmailbak`date +%y%m%d`

#cp notesdata to notesdatabak
echo `date` >> $logfile
echo "wulmail backup start" >> $logfile
cp -rf /notesdata /notesdatabak/$bakfile
if [ $? -eq 0 ];then
    echo "cp data finish" >> $logfile
else
    echo "cp fail" >> $logfile
    exit 1
fi

#tar wulmail data
echo "tar data start" >>$logfile
tar -zcf /notesdatabak/$bakfile.tar.gz /notesdatabak/$bakfile
if [ $? -eq 0 ];then
        echo "tar data finish" >> $logfile
    rm -rf /notesdatabak/$bakfile
else    
        echo "tar fail" >> $logfile
        exit 2
fi

#bakcup wulmail data to backupserver
echo "mv backup wulmail data to backupserver" >>$logfile
mv /notesdatabak/$bakfile.tar.gz /wulmailbackup
if [ $? -eq 0 ];then
        echo `date` >> $logfile
        echo "wulmail backup sucessful" >> $logfile
else    
        echo "mv fail,backup end" >> $logfile
        exit 3
fi

eip(server 2008服务器均雷同,traveler配置此次省略):

1、windows上安装nfs服务
servermanagercmd.exe -install FS-NFS-Servicesd.exe -install FS-NFS-Services
net use /persistent:yes #让磁盘隐射永久有效 重启存在

2、bat脚本编写并添加至执行计划
@echo off
mount -u:root  -p:oracleadmin 10.55.2.83:/home/eipbackup z:
echo %date% %time% >>z:\eipbak%Date:~2,2%%Date:~5,2%%Date:~8,2%.log
echo eip backup start >>z:\eipbak%Date:~2,2%%Date:~5,2%%Date:~8,2%.log

md z:\eipbak%Date:~2,2%%Date:~5,2%%Date:~8,2%

xcopy D:\Lotus z:\eipbak%Date:~2,2%%Date:~5,2%%Date:~8,2%\ /S/E >>z:\eipbak%Date:~2,2%%Date:~5,2%%Date:~8,2%.log
echo %date% %time% >>z:\eipbak%Date:~2,2%%Date:~5,2%%Date:~8,2%.log
echo eip backup sucessful >>z:\eipbak%Date:~2,2%%Date:~5,2%%Date:~8,2%.log

umount z:

ISO(ISO1 2相同配置)

1、bat脚本编写并添加至执行计划
@echo off
net use z: \\10.55.2.83\wuwis2backup "******" /user:"wuwis2"
echo %date% %time% >>z:\wuwis2bak%Date:~2,2%%Date:~5,2%%Date:~8,2%.log
echo wuwis2 backup start >>z:\wuwis2bak%Date:~2,2%%Date:~5,2%%Date:~8,2%.log

md z:\wuwis2bak%Date:~2,2%%Date:~5,2%%Date:~8,2%

xcopy D:\Lotus z:\wuwis2bak%Date:~2,2%%Date:~5,2%%Date:~8,2%\ /S/E >>z:\wuwis2bak%Date:~2,2%%Date:~5,2%%Date:~8,2%.log
echo %date% %time% >>z:\wuwis2bak%Date:~2,2%%Date:~5,2%%Date:~8,2%.log
echo wuwis2 backup sucessful >>z:\wuwis2bak%Date:~2,2%%Date:~5,2%%Date:~8,2%.log

net use z: /delete


本文出自 “Open World” 博客,请务必保留此出处http://voidyao000.blog.51cto.com/12458042/1917630

最近为公司制定的备份解决方案

标签:samba   backup   tar   nsf   

原文地址:http://voidyao000.blog.51cto.com/12458042/1917630

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!