#!/bin/bash
# 备份源文件夹路径
source_paths=(
/www/backup/panel
/www/backup/database
/www/backup/path
/www/backup/site
)
RM_DIR=("/www/backup/panel" )
RM_DIR=("/www/wwwlogs/free_waf_log" )
RM_DIR=("/www/wwwlogs" )
#find $RM_DIR -type f -mtime +1-exec rm {} \;
#find $source_paths -type f -mtime +1 -exec rm {} \;
# 备份挂载目标文件夹路径
backup_path=/mnt
# 遍历需要备份的路径并复制到把备份挂载路径
for source_path in "${source_paths[@]}";
do
# 检查源文件夹是否存在
if [ -d "$source_paths" ]; then
# 检查weddav是否已挂载
if ! mount | grep $backup_path > /dev/null; then
# weddav未挂载,尝试自动挂载
#前提需要在/etc/davfs2/secrets 末尾添加:相关账户密码!
mount -t davfs -o uid=0,gid=0,rw,file_mode=0777,dir_mode=0777 http://www.*****.top:1029/ssd2/work/baidu $backup_path
fi
# 源文件夹存在,复制到weddav挂载路径
cp -r -u $source_path $backup_path
# 卸载weddav挂载路径
umount -f davfs http://www.*****.top:1029/ssd2/work/baidu $backup_path
# 自动删除7天前的备份文件
else
# 源文件夹不存在,给出错误提示
echo "Error: Source folder $source_path not found."
fi
done
exit 0
这个脚本,几乎可以满足我备份的需求了,但有些需要优化。
疑问1.
所有的文件同步到wedav,卸载之后,需要自动删除多少天内,指定文件夹的文件,
find $RM_DIR -type f -mtime +1-exec rm {} \;
全部备份完成后,我用了这个命令,并不生效,不知道什么问题,请指点一下。
疑问2.
在这个系统执行这些命令的时候,出错了,并不会同步。
[root@iZj6c7h4enicwfgrnta8wzZ ~]# cat /proc/version
Linux version 3.10.0-1160.92.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Tue Jun 20 11:48:01 UTC 2023
命令和ubuntu的一样,可是在这个系统就出错
出错提示:
[root@iZj6c7h4enicwfgrnta8wzZ ~]# ./aliyun_backup.sh
/sbin/mount.davfs: Warning: can't write entry into mtab, but will mount the file system anyway
umount: davfs: mountpoint not found
umount: /mnt:未挂载
/sbin/mount.davfs: found PID file /var/run/mount.davfs/mnt.pid.
Either /mnt is used by another process,
or another mount process ended irregular
umount: davfs: mountpoint not found
umount: http://www.***.top:1029/ssd2/work/aliyun: mountpoint not found
umount: /mnt:未挂载
/sbin/mount.davfs: found PID file /var/run/mount.davfs/mnt.pid.
Either /mnt is used by another process,
or another mount process ended irregular
umount: davfs: mountpoint not found
umount: http://www.***.top:1029/ssd2/work/aliyun: mountpoint not found
umount: /mnt:未挂载
/sbin/mount.davfs: found PID file /var/run/mount.davfs/mnt.pid.
Either /mnt is used by another process,
or another mount process ended irregular
umount: davfs: mountpoint not found
umount: http://www.***.top:1029/ssd2/work/aliyun: mountpoint not found
umount: /mnt:未挂载
[root@iZj6c7h4enicwfgrnta8wzZ ~]#
请问是为何?