Label archiving: Database backup script

One click backup script of Web MySQL

Script property description:

  • Backup website data/database data to remote FTP server;
  • Support CentOS/Fedora/Ubuntu/Debian system;
  • Support crontab scheduled backup;
 #!/ bin/env bash #Install FTP tools according to the system version command -v yum >/dev/null 2>&1 && apt-get -y install ftp command -v apt-get >/dev/null 2>&1 && yum -y install ftp #Database name/account/password #Fill in according to the actual information DBName=" renwole " DBUser=" renwole " DBPass=" Renwole1!@# " #Ftp remote host/port/account/password #Fill in according to the actual information FtpHost=" renwole.com " FtpPort=" twenty-one " FtpUser=" renwole " FtpPass=" Renwole1!@# " FtpDir=" /wwwroot/Renwolecom " #Web name/directory and backup path #Modify according to the actual web path WebName=" Renwole " WebDir=" /apps/web/renwole.com " mkdir /backup BakDir="/backup" #Package, backup and upload the database and website data to the ftp server command -v mysqldump >/dev/null 2>&1 || { echo "Not found MySQL/MariaDB ENV"; kill -9 $$; } mysqldump -u${DBUser} -p${DBPass} ${DBName} >${BakDir}/$ {DBName}- $(date +"%Y%m%d").sql tar zcf ${BakDir}/$ {WebName}- $(date +"%Y%m%d").tar.gz ${WebDir} ftp -v -n ${FtpHost} ${FtpPort}<< EOF user ${FtpUser} ${FtpPass} type binary passive cd ${FtpDir} put ${BakDir}/$ {DBName}- $(date +"%Y%m%d").sql put ${BakDir}/$ {WebName}- $(date +"%Y%m%d").tar.gz bye EOF

Download the data backup script:

 curl -O  https://renwole.com/sh/backup.sh  && chmod +x backup.sh

Set crontab scheduled task:

 #Backup at 2:00 am every day and push it to the FTP server echo "0 0 2 * * /backup/backup.sh " >> /var/spool/cron/root

notes : Content annotated gules Some of them need to be modified according to their own actual information , others do not need to be modified. In addition, you can also modify ftp and support the sftp security backup mode. Or delete ftp and only back up the data to the local specified directory.