WordPress Encrypted Backups • WordPress Help

Precisely because the backups contain sensitive information seems smart encrypt your SQL backups … or any backup of your site Do not you think?

What we are going to see today is a useful console script to make safe backups of the files and the database of your WordPress blog in a simple way and that does not complicate you . You only have to generate a GPG key once, enter it in 3 configurations and from that moment it can be executed by any user, and from wherever you want.

What do you do?

Once you execute it, this script asks you the location of the root folder of your blog and also where is your file wp-config.php . It will also ask you for a UID (user ID) encryption. Then the script saves those settings in a file called .sbackup so that the next time you run the script runs without having to re-enter that information, very useful for cronjobs or for quick and simple backups at will. Another interesting feature of this script is that it automatically analyzes your file wp-config.php to extract the name of the MySQL database the user, server and password. With this you do not compromise your security while you do not waste time typing that data manually.

What is backup?

This script creates a tar and gzip file of all your root directory in the folder ~ /backups/domain.com/domain.com-date.tgz y also creates a backup of your WordPress database in an ideal format to restore it afterwards. Both files are encrypted using your GPG key and can be downloaded safely because the password and the key are required to decrypt them.

Generating the GPG Key

If you do not have a key configured yet your shell account executes this command by remembering (or pointing) the UID you enter in the script.
[code] gpg -gen-key [/code]

Decrypting the Files

[code] gpg -r UID -output FILENAME.tgz -decrypt FILENAME.tgz .asc [/code]

The Script

[code] #! / bin / bash
# SiteBack Version 3.1, 2008-07-04
# GNU Free Documentation License 1.2
# 07-04-08 – AskApache (www.askapache.com)
# Translated by WordPress Help (ayudawordpress.com)
umask 022

### CONSOLE OPTIONS
set + o noclobber # allowed to clobber files
set + o noglob # globbing on
set + o xtrace # change to – to enable tracing
set + o verbose # change to – to enable v erbose debugging
set -e # abort on first error

shopt -s extglob

################### ########################################################################################## – = – = – = – = – = – = – = – = – = – #
###
### CONFIGURATIONS
###
######## #################################################################################################### ############ == – == – == – == – == – == – == – == – == – == #

DT = $ (date +% x); DT = $ {DT // /}
DTX = $ (date +% x-% H% M); DTX = $ {DTX // /}
BDIR = $ {HOME} / backups
RUN_FILE = $ {BDIR} / $$. Bk.log
MY_CONFIG = ". Sbackup"
DOMAIN =; DB_NAME =; DB_USER =; DB_PASSWORD =; DB_HOST =; WP_CONFIG =; SQL_DEST =; ARC_DEST =; ENCRYPT_USER =
E_SUCCESS = 0; E_YN = 0; E_YES = 251; E_NO = 250; E_RETURN = 65; C0 = ; C1 =; C2 =; C3 =; C4 =; C5 =; C6 =; C7 =; C8 =; C9 =

################ #################################################################################################### ##### – = – = – = – = – = – = – = – = – = – = – #
###
### FUNCTIONS
###
# #################################################################################################### ############################################################################################### – == – == #

# – = – = – = – = – = – = – = – = – = – = – #
# script_title
# == – == – == – == – == – == – == – == – == – == – == #
function script_title () {
# ESTABLISH TITLE AND COLORS OF THE WINDOW
case $ { TERM: -dummy} in
xterm * | vt * | ansi | rxvt | gnome *)
C0 = " 033 [0m";C1="33[1;30m";C2="33[1;32m";C3="33[0;32m";C4="33[1;37m"
C5 = " 033 [0;36m";C6="33[1;35m";C7="33[0;37m";C8="33[30;42m";C9="33[1;36m"
esac
echo -e" $ {C1} __________________________________________________________________________ "
echo -e" | $ {C2} ___ __ ___ __ $ {C1} | "
echo -e" | $ {C2} / _ | ___ / / __ / _ | ___ ___ _____ / / ___ $ {C1} | "
echo -e" | $ {C2} / __ | (_- >> $ {C4} $ {1} $ {C0} n n "; ;;
" info ") echo -e" $ {C6} => $ {C4} $ {1} $ {C0} "; ;;
"item") echo -e "$ {C4} – $ {C0} $ {1}"; ;;
esac
}

# – = – = – = – = – = – = – = – = – = – = – #
# yes_no
# == – == – == – == – == – == – == – == – == – == – == #
function yes_no () {
local ans
echo -en "$ { 1} [y / n] "; read -n 1 ans
case "$ ans" in
n | N) E_YN = $ E_NO ;;
and | Y) E_YN = $ E_YES ;;
esac
} [19659003] # – = – = – = – = – = – = – = – = – = – = – #
# do_sleep
# == – == – == – == – == – == – == – == – == – == – == #
function do_sleep () {
local END DIFF
echo -en "$ {C5} $ {3: -.}"; while [ -r “$RUN_FILE” ]; do sleep $ {2: -3}; echo -in "$ {3: -.}"; done;
echo -e "$ {C0}"; sleep 1; END = $ (date +% s); DIFF = $ (($ END – $ START))
echo -e " n $ {C8} [T: ${SECONDS}] COMPLETED IN $ {DIFF} SEC $ {C0} n n "; sleep 1;
return 0;
}

# – = – = – = – = – = – = – = – = – = – = – #
# get_settings
# == – == – == – == – == – == – == – == – == – == – == #
function get_settings () {
local cha HOSTED_SITES G
clear ; script_title
if [[ -r “$MY_CONFIG” ]]; then
OIFS = $ IFS; while IFS =: read DOMAIN DOMAINROOT WP_CONFIG ENCRYPT_USER; do
DOMAIN = $ {DOMAIN}; DOMAINROOT = $ {DOMAINROOT}; WP_CONFIG = $ {WP_CONFIG}; ENCRYPT_USER = $ {ENCRYPT_USER}; E_YN = $ E_YES; break
done "
read-e cha; threw out; [[ ${#cha} -gt 2 ]] && eval "$ a" = $ cha
done
yes_no "ARE THESE CONFIGURATIONS CORRECT?"
done

echo -e "$ {DOMAIN}: $ {DOMAINROOT}: $ { WP_CONFIG}: $ {ENCRYPT_USER} "> $ MY_CONFIG
}

# – = – = – = – = – = – = – = – = – = – = – #
# exit_cleanup
# == – == – == – == – == – == – == – == – == – == – == #
function exit_cleanup () {
cd $ OLDPWD
[[ -r ${SQL_DEST} ] ] && rm $ {SQL_DEST}
[[ -r ${ARC_DEST} ]] && rm $ {ARC_DEST}
}

################## #################################################################################################### ############### MAIN CODE [#
# ################################################################################################## ##
################################################################################################# #################################################################################################### #########

# = # GET THE SCRIPT OFF BY THE USER
trap exit_cleanup SIGHUP SIGINT SIGTERM

# = # NECESSARY THE MAIN SCRIPT
renice 19 -p $$ &> / dev / null

cd dirname $ 0

get_ settings

pm "CREATING SQL BACKUP"
mysqldump -opt -u $ {DB_USER} -p $ {DB_PASSWORD} -h $ {DB_HOST} -r $ {SQL_DEST}
-add-drop- table $ {DB_NAME} 1> & 2 &> / dev / null && sleep 2 1> & 2 &> / dev / null && rm $ {RUN_FILE} 2> & 1 &
do_sleep 1 1 ":"

pm "ENCRYPTING SQL BACKUP "
gpg -armor -recipient $ {ENCRYPT_USER} -output $ {SQL_DEST} .asc -encrypt $ {SQL_DEST}
1> & 2 &> / dev / null && sleep 2 1> & 2 & > / dev / null && rm $ {RUN_FILE} 2> & 1 &
do_sleep 1 1 ":"; rm $ {SQL_DEST}

pm "CREATING ARCHIVE BACKUP"
tar -czf $ {ARC_DEST}. 1> & 2 &> / dev / null && rm $ {RUN_FILE} 2> & 1 &
do_sleep 1 5 ":"

pm "ENCRYPTING BACKUP OF FILE"
gpg -armor -recipient $ {ENCRYPT_USER} – output $ {ARC_DEST} .asc -encrypt $ {ARC_DEST}
1> & 2 &> / dev / null && rm $ {RUN_FILE} 2> & 1 &
do_sleep 1 1 ":"; rm $ {ARC_DEST}

echo -e "$ {C1} __________________________________________________________________________"
echo -e "| | "
echo -e" | $ {C4} COMPLETED WITH SUCCESS $ {C1} | "
echo -e" $ {C1} __________________________________________________________________________ $ {C0} n n "

cd $ OLDPWD

exit $?
[/code]
script wonder has been created in AskApache and you can also download it directly at this link .

NOTICE : this publication is from two years ago or more. If it's a code or a plugin it might not work in the latest versions of WordPress, and if it's a news story it might be obsolete. Then do not say we have not warned you.

Loading …

That may also help you: