Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write a linux database backup and upload a script through ftp

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "how to write linux database backup and upload scripts through ftp". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The code is as follows:

#! / bin/bash

# author: 505056357@qq.com

Echo "backup job start"

# set the website directory to be backed up, that is, the root directory of the website

File=/home/wwwroot/default

# set up a local backup directory for storing packaged files

Backpath=/home/wwwroot/bkdata/

Dbuser=root

# data password, remember to use single quotation marks to enclose the whole password, if there are single quotation marks in the password, use double quotation marks, hey

Dbpwd='123456'

Dbname=car

Domain=192.168.0.187

User=ftpuser

Userpwd='123456'

Bkdate=$ (date +% Y%m%d)

Sqlfile_sql=$ {dbname} _ ${bkdate} .sql

Sqlfile_gz=$ {dbname} _ ${bkdate} .tar.gz

Sqlfp=$ {backpath} ${bkdate} / $sqlfile_sql

If [- e $backpath$ {bkdate}]

Then

Echo $backpath is exists.

Else

Mkdir-p $backpath$ {bkdate}

Fi

# perform database backup and / apps/mysql/bin/mysqldump change to the path of your actual environment

/ apps/mysql/bin/mysqldump-u $dbuser-p$dbpwd $dbname > ${sqlfp}

# compress the database files after backup, or compress the database files directly by adding parameters during database backup

Tar zcf $backpath$ {bkdate} / $sqlfile_gz-C ${backpath} ${bkdate} ${sqlfile_sql}

# Delete files that are not compressed SQL

Rm-f ${sqlfp}

# format of generated file name: web_ website directory name _ 20130419.tar.gz

Fn=web_$ {file##*/} _ ${bkdate} .tar.gz

Tar zcf $backpath$ {bkdate} / $fn-C ${file%/*} ${file##*/}

# the following actions are used to automatically connect and upload local files to a remote server for FTP

/ usr/bin/lftp ${domain}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report