CONTACTUS
Live Chat
Chat now with us
Email Us
Send us an email, and we'll get back to you soon
Call Us
Reach out to us now

  Home > Knowledge Base >  服务器教程 >  Linux下定时备份文件

Linux下定时备份文件

2020-06-09

Linux下定时备份文件

将文件目录 /home/backups/balalala 备份到/home目录下


创建脚本  

touch 路径、文件名.sh

touch /home/backup.sh

vi /home/backup.sh


脚本内容  

#! /bin/sh

mkdir /home/fcc

   创建一个文件(备份的路径)

   cp -r /home/backups/balalala /home/fcc

   数据存在backups目录下,备份到fcc目录下,先把数据拷贝过来

   tar -zcpvf /home/backup$(date +%Y%m%d) .tar.gz /home/fcc

   将数据所在文件fcc打包

   rm -rf /home/fcc

   删除文件内容

   find ./ -mtime +30 -name ‘’*.tar.gz‘’ -exec rm -rf {} rm -rf {} \;

   删除改文件夹下超过30天的文件


执行脚本文件  

  sh /home/backup.sh


设置定时执行脚本  

安装cron

检查服务状态:service crond status

修改crontab内容

命令crontab -e

进入后写脚本时间:0 0 /7 * /home/backup.sh  (分 时 日 月 周)

设置为每7天执行一次脚本

保存wq

重启cron服务

service cron restart


Previous:

It's the first one

Next:

It's the last one

If you find 【Linux下定时备份文件】 useful, please share it with your friends. Thank you!

Copy link