Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement VPS Free backup script under linux

Shulou Source: shulou.com Published: 2022-05-31 21:48:53 12月03日 Update

Today, I would like to share with you the relevant knowledge of how to achieve VPS free backup script under linux. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article.

The code is as follows:

#! / bin/bash

# set-x

Time= `date +% y% m% d`

# here is the backup mysql

[!-e / backup/sqltmp] & & mkdir-p / backup/sqltmp # create a temporary backup mysql directory

[!-e / backup/backsql] & & mkdir-p / backup/backsql # create a directory where mysql backups are stored

Cd / backup/sqltmp

Sql= `mysqlshow-u username-p password | grep-v + | grep-ev "data | information | mysql | test" | awk {'print $2'} `# query website databases other than system data in mysql database. You can modify them here as needed.

For sqlname in $sql

Do

Mysqldump-u username-p password $sqlname > $sqlname.sql

Done

Tar zcvf backsql.$time.tar.gz * .sql

Rm-rf * .sql

Mv *.. / backsql/.

Cd..

Rm-rf sqltmp

# here is the backup website

[!-e / backup/webtmp] & & mkdir-p / backup/webtmp # create a temporary backup web file directory

[!-e / backup/backweb] & & mkdir-p / backup/backweb # create a directory where web file backups are stored

Cd / backup/webtmp

Tar zcvf backweb.$time.tar.gz / home/*

Mv *.. / backweb/.

Cd..

Rm-rf webtmp

The following is a script for uploading a backup site to the godaddy space via ftp:

The copy code is as follows:

#! / bin/bash

Backsql= `CD / backup/backsql;ls-r backsql* | head-1` # because the latest file is backed up every day

Backweb= `CD / backup/backweb;ls-r backweb* | head-1`

Ftp-n

Tags: Backup file code script directory knowledge article password data user user name website path content database space Tiandu different big time-saving Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information Huawei MariaDB Docker