客户需求对oracle数据库做一个跨机房的备份,原环境已做rman备份和每天expdp全库导出,远端只有虚拟化环境,可提供一个虚拟机,2个机房间网络互通。
首先配置nfs服务端
查看操作系统版本
[root@nas199 ~]# more /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
yum包
[root@nas199 ~]# yum -y install nfs-server portmap showmount
把NFS设为开机自启:
[root@nas199 ~]# systemctl enable nfs && systemctl start nfs
将RPC设为开机自启:
[root@nas199 ~]# systemctl enable rpcbind && systemctl start rpcbind
关闭防火墙
[root@nas199 ~]# systemctl stop firewalld && systemctl disable firewalld
查看数据库的oracle用户id和组id
[root@db1 ~]# id oracle
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba),54323(oper),54327(asmdba),54329(asmadmin)
编辑/etc/exports,如下所示
[root@nas199 ~]# cat /etc/exports
/backup/ 172.100.18.196(rw,sync,no_root_squash,anonuid=54321,anongid=54321)
/backup/ 122.100.18.197(rw,sync,no_root_squash,anonuid=54321,anongid=54321)
修改/etc/exports后重新加载
[root@nas199 ~]# exportfs -rv
exporting 172.100.18.196:/backup
exporting 172.100.18.197:/backup
[root@nas199 ~]#
在db1上操作
[root@db1 ~]# showmount -e 172.100.18.199
Export list for 172.100.18.199:
/backup 172.100.18.197,172.100.18.196
[root@db1 ~]# mkdir /nasbackup
[root@db1 ~]# mount 172.100.18.199:/backup /nasbackup
[root@db1 ~]# chown -R oracle:oinstall /nasbackup
[root@db1 ~]# chmod -R 775 /nasbackup
[root@db1 ~]# df -ht nfs4
Filesystem Size Used Avail Use% Mounted on
nasserver:/backup 11T 815G 11T 8% /nasbackup
[root@db1 ~]#
orcl1:/home/oracle@db1> crontab -l
10 02 * * * /home/oracle/copy_to_nasbackup.sh &
orcl1:/home/oracle@db1> cat /home/oracle/copy_to_nasbackup.sh
#!/bin/bash
rsync -vzurtopg --progress /backup/orcl /nasbackup
/bin/find /nasbackup/orcl/rmanbackup/ -type f -name "rman_*" -mtime +60 -exec rm {} \;
/bin/find /nasbackup/orcl/logicbacup/ -type f -name "orcl_*" -mtime +60 -exec rm {} \;