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
#!/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
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!