How to back up files in linux

王林
Release: 2019-12-06 13:27:32
Original
7137 people have browsed it

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

How to back up files in linux

# #After the file is created, enter the file, enter vi /home/backup.sh, and click the Enter key

How to back up files in linux

Online video tutorial sharing:

linux video tutorial

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天的文件
Copy after login

Enter sh /home/beifen.sh again in the terminal, click the Enter key to enable the script

How to back up files in linux

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

How to back up files in linux

Recommended related articles and tutorials:

linux tutorial

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template