Linux wget auto login and backup database

#!/bin/bash

# 这是一份本来打算采用自动备份数据的代码,由于测试过程中出现了无法连接的问题,导致不能测试,
# 于是最后放弃了这份代码的进一步的开发,但是记录还是有必要的

login_url='xxxxxxxxx:2083/login/?login_only=1'
cookie_file='cookie'
login_params="--save-cookies $cookie_file --keep-session-cookies --post-data='user=z&pass=q' --referer='xxxxxxxx:2083/' --no-check-certificate"
download_params="--save-cookies $cookie_file --keep-session-cookies --load-cookies $cookie_file --referer='xxxxxxx:2083/{{SESSION_ID}}/frontend/paper_lantern/backup/index.html' --no-check-certificate"
backup_url='xxxxxxxx/{{SESSION_ID}}/getsqlbackup/z_zengjf.sql.gz'

login() {
    wget $login_params "$login_url" -O -
    exit
    #return_html=$(wget $login_params "$login_url 2> /dev/null" -O -)
    session_id=$(echo "$return_html" | awk -F/ '{print $2}')
}

download() {
    url=$(echo "$backup_url" | sed -r "s/\{\{SESSION_ID\}\}/$session_id/")
    params=$(echo "$download_params" | sed -r "s/\{\{SESSION_ID\}\}/$session_id/")
    file_name="blog_db_$(date +'%Y%m%d%H%M%S').sql.gz"
    wget $params "$url" -O $file_name
}

clean() {
    rm -f $cookie_file
}

login
#download
#clean

 

posted on 2015-10-25 22:03  zengjf  阅读(295)  评论(0编辑  收藏  举报

导航