自动备份 wiki 的 shell
跳到导航
跳到搜索
#!/bin/bash
# Script description
# Define variables
mediawiki_container_id="aade5ae73079"
mysql_container_id="fca2c79917cf"
date_command="date +%Y%m%d"
date_str=$($date_command)
mediawiki_command_arg="mediawiki:$date_str"
mysql_commit_command="docker commit -p $mysql_container_id mysql:$date_str"
mediawiki_commit_command="docker commit -p $mediawiki_container_id mediawiki:$date_str"
mysql_backup_image_id=""
mediawiki_backup_image_id=""
mysql_tag_command="docker tag $mysql_backup_image_id registry.cn-hangzhou.aliyuncs.com/www_jihongchang_top/wiki:mysql_$date_str"
# Define functions
#commit
function commit() {
commit_mysql
commit_mediawiki
}
function commit_mysql() {
local result=$($mysql_commit_command)
echo "$result"
mysql_backup_image_id=$(echo "$result"|grep -oP ":([0-9a-z]{12})"|grep -oP "[0-9a-z]{12}")
# echo "$mysql_backup_image_id"
}
function commit_mediawiki() {
local result=$($mediawiki_commit_command)
echo "$result"
mediawiki_backup_image_id=$(echo "$result"|grep -oP ":([0-9a-z]{12})"|grep -oP "[0-9a-z]{12}")
# echo "$mediawiki_backup_image_id"
}
#tag
function tag_mysql() {
local mysql_tag_command="docker tag $mysql_backup_image_id registry.cn-hangzhou.aliyuncs.com/www_jihongchang_top/wiki:mysql_$date_str"
$mysql_tag_command
}
function tag_mediawiki() {
local mediawiki_tag_command="docker tag $mediawiki_backup_image_id registry.cn-hangzhou.aliyuncs.com/www_jihongchang_top/wiki:mediawiki_$date_str"
$mediawiki_tag_command
}
function tag() {
tag_mysql
tag_mediawiki
}
#push
function push_mysql() {
mysql_push_command="docker push registry.cn-hangzhou.aliyuncs.com/www_jihongchang_top/wiki:mysql_$date_str"
# echo "$mysql_push_command"
$mysql_push_command
}
function push_mediawiki() {
mediawiki_push_command="docker push registry.cn-hangzhou.aliyuncs.com/www_jihongchang_top/wiki:mediawiki_$date_str"
$mediawiki_push_command
}
function push() {
push_mysql
push_mediawiki
}
#function test_function() {}
# Main code
echo "Starting script execution..."
# Call functions
commit
tag
push
echo "Script execution completed."
exit 0