Linux expect automatically download data backup without losing password (new)

Source: Internet
Author: User
Tags sleep phpmyadmin

Here is the script implementation process:
1. Automatically package the backup on the server to a Web directory (of course this web directory is inaccessible to other people), so that the script to download.
2. Download the backup package on the local server, unzip it and copy it into a dedicated backup directory.
3. When the above two steps are completed, we will remove the backup package on the server to avoid leakage.

Here's the script:
1. This is to filter out the latest backup on the server and package the latest backup to the Web directory:
Cat copy_bakfile.sh

The code is as follows Copy Code

#!/bin/bash
location= "/root/sqlbak/"
Newfile= "/root/newfile"
File= '/root/newfile '
web= "/var/www/vhosts/wwwroot/phpmyadmin"
Rm-f ${file}/*
#file =$ (Find $location-type f-mtime-1)
file=$ (Find $location-type f-mmin-60)
CP $file $newfile
Sleep 3
Ls-l $newfile |awk ' {print $} ' |xargs tar-c $newfile/-czf $web/bak.tar.gz

2. This is the download Backup package script (first connected to the server to perform copy_bakfile.sh to filter out the latest backup, and package to the Web directory, and the packaged bak.tar.gz download to the local)
Cat Down.exp

The code is as follows Copy Code

#!/usr/bin/expect-f
Set Timeout-1
Set passwd PASSWORD
Spawn ssh-p18330 Root@124.248.xxx.xxx
Expect {
"Yes/no" {send "YESR"; Exp_continue}
"Password:" {send "$PASSWDR"}
}
Expect "*#*" {send "Sh/root/soft_shell/copy_bakfile.shr"}
Expect "*#*" {send "Exitr"}
Spawn Axel-q Http://blog.slogra.com/bak.tar.gz-o/root/sqlbak/
Expect EOF

3. This is the extract backup package script
Cat process.sh

  code is as follows copy code

#!/bin/ Bash
pid= ' ps-c Axel--no-header|wc-l '
file= ' find/root/sqlbak/-name bak.tar.gz.st|wc-l '
list= '/root/sqlba K "
newfile="/data/onlinesqlbak "
date=" ' Date ' +%y-%m-%d%h:%m:%s ' ""
if [[$pid-eq 0]] | | [[$file-eq 0]];then
expect/root/soft_shell/delbak.exp
#tar zxf $list/*
Tar zxf $list/*-C $newfile/
SL EEP
rm-f $list/bak.*
#for i in $list/*;d o cp-r $i $newfile/;d one
#sleep 1
#rm-F $list/*.gz
else< br> echo "$date | Load download ... ">>/root/processlog.txt
Fi

S: I believe we all know how to confirm whether there is download, the script to check whether there is download down.exp, confirmed that the download was finished before decompression bak.tar.gz, and the extracted copy to a special backup directory, and execute the Delete script to delete the bak.tar.gz package in the Web directory on the server.

4. This is the script that deletes the BAK.TAR.GZ package on the server
Cat Delbak.exp

The code is as follows Copy Code

#!/usr/bin/expect-f
Set Timeout-1
Set passwd PASSWORD
Spawn ssh-p18330 Root@124.248.xxx.xxx
Expect {
"Yes/no" {send "YESR"; Exp_continue}
"Password:" {send "$PASSWDR"}
}
Expect "*#*" {send "Rm-f/var/www/vhosts/wwwroot/phpmyadmin/bak.tar.gzr"}
Expect "*#*" {send "Exitr"}
Expect EOF

Finally, to use these scripts, remember to install the Axel and expect tools, or you will not be able to put down the backup package.

Original from: http://blog.slogra.com/post-517.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.