#!/bin/sh
#此脚本用于将linux系统备份到windows共享文件夹或NAS服务器,
#原理是1.备份系统到本地2.挂载远程路径到linux3.将备份文件复制到该路径下4.删除过期的备份文件、断开连接
#username|password分别为访问用户,准备登陆资料
username='backup'
password='backup'
#不同系统需修改
remotepath="//172.29.60.22/backup/linux/oracle"
#localpath:/backup22用于挂载备份服务器共享文件夹,先umount路径避免异常
localpath="/backup22"
umount $localpath
#挂载远程目录到linux服务器
mount -t cifs -o username=$username,password=$password $remotepath $localpath
#备份到本地backupToFile
localBackupPath="/usr/localbackup"
backupToFile=$localBackupPath/$HOSTNAME"_backup`date +%y%m%d`.tgz"
#3天前的文件远程文件夹备份文件,删除
#beforeThreeDayFile=$remotepath"/backup`date -d -7day +%y%m%d`.tgz"
beforeThreeDayFile=“/backup22/oradb_backup`date -d -8day +%y%m%d`.tgz”
#remotepath=/backup22/oradb_backup`date -d -8day +%y%m%d`.tgz
if [ ! -d "$localBackupPath" ]; then
mkdir $localBackupPath
fi
tar -cvpzf $backupToFile --exclude=/proc --exclude=/lost+found --exclude=/mnt --exclude=/sys --exclude=/media --exclude $localBackupPath --exclude $localpath /
#logFile为远程目录的一个文件,用于判断路径是否成功挂载
logFile="/backup22/backup_log_in22.txt"
#如果挂载成功则复制到22,否则写入log
if [ ! -f "$logFile" ]; then
echo -e "`date +%y%m%d_%T`挂载失败\n">> "/backup22/backup_log_local.txt"
echo -e "`date +%y%m%d_%T`挂载失败\n"
else
echo -e "`date +%y%m%d_%T`已挂载备份服务器到本地\n" >> "$logFile"
#复制备份文件到22服务器
cp $backupToFile $localpath
rm -f $backupToFile
rm -f
echo -e "\n三天前的文件已删除"$beforeThreeDayFile >> "$logFile"
echo -e "\n`date +%y%m%d_%T`备份成功_"$backupToFile >> "$logFile"
echo -e "\n`date +%y%m%d_%T`备份成功_"$backupToFile
fi
linux系统备份到windows共享文件夹或NAS服务器
最新推荐文章于 2024-06-20 14:29:31 发布