Home >Operation and Maintenance >Linux Operation and Maintenance >How to back up files in linux
First we need to create a backup script, open the terminal, enter touch /home/beifen.sh, and click the Enter key
# #After the file is created, enter the file, enter vi /home/backup.sh, and click the Enter key Online video tutorial sharing: Enter in the opened script:#!/bin/sh mkdir /home/beifen #创建一个临时文件(要保存备份的路径) cp -r /home/backups/balalala /home/beifen #数据存在backups目录下,备份到beifen目录下,所以先将数据拷过来 tar -zcPvf /home/backup$(date +%Y%m%d).tar.gz /home/beifen #将数据所在文件夹beifen打包 rm -rf /home/beifen/ #删除临时文件内容 find ./ -mtime +30 -name "*.tar.gz" -exec rm -rf {} \; #删除改文件夹下超过30天的文件Enter sh /home/beifen.sh again in the terminal, click the Enter key to enable the script Enter crontab -e in the terminal, click the Enter key, and then enter 0 0 /10 * sh /home/beifen.sh, here refers to executing the beifen.sh script every 10 days Recommended related articles and tutorials:
The above is the detailed content of How to back up files in linux. For more information, please follow other related articles on the PHP Chinese website!