Hallo
Ich poste mal ein kleines Backup-Script für WP (das so viel verwendete)...
Im Script muß man im Grunde nichts angeben. Es holt sich die aktuelle WP-Config automatisch.
Mann sollte sich ein Verzeichnis erstellen, in welches die WP-Backups rein gespeichert werden.
Das sollte man eventuell auch per .htaccess "unzugänglich" machen -- aber mehr ist nicht nötig.
Alle Dateien, welche das Script anlegt haben das Recht 400 -- also nur der erstellende Shell-User darf lesend zugreifen.
einfach eine beliebige Datei mit Endung sh im WP-Root erstellen (Rechte: 700) und diesen Inhalt reinkopieren:
#!/bin/bash
#System-Werte
#root_path=($(pwd))
root_path="$( cd "$( /usr/bin/dirname "$0" )" && pwd )"
timestamp=$(date +"%Y-%m-%d_%H-%M")
# Angabe des Pfade relativ zum
# Script-Pfad MIT abschliessendem / !!
backup_path=''
# Config-Variablen
db_user=''
db_pass=''
db_name=''
db_host=''
db_file=''
# TAR-Variablen
tar_file=''
tar_options=''
tar_log=''
tar_db=''
tar_config='wp-config.php'
tar_rights='400'
config_file=${root_path}'/'${tar_config}
backup_include='wp-content/* noch_ein_verz/*'
function extract() {
php_zeile=${2}
max=${#2}-4
echo ${php_zeile:1:$max}
}
function get_config_data() {
while read zeile
do
if [[ ${zeile} == *'DB_NAME'* ]]; then
db_name=$(extract ${zeile})
fi
if [[ ${zeile} == *'DB_USER'* ]]; then
db_user=$(extract ${zeile})
fi
if [[ ${zeile} == *'DB_PASSWORD'* ]]; then
db_pass=$(extract ${zeile})
fi
if [[ ${zeile} == *'DB_HOST'* ]]; then
db_host=$(extract ${zeile})
fi
done < ${config_file}
}
function database_create_backup() {
tar_db=${backup_path}'database_'${db_name}'_'${timestamp}'.sql'
tar_log=${root_path}'/'${backup_path}${db_name}'_error_'${timestamp}'.log'
db_file=${root_path}'/'${tar_db}
echo "Backup-Datei: ./${tar_db}" | tee -a ${tar_log}
mysqldump --single-transaction -u ${db_user} -p${db_pass} ${db_name} > ${db_file} | tee -a ${tar_log}
bytes=$(du -b ${db_file} | sed 's/\([0-9]*\)\(.*\)/\1/')
mbytes=$((bytes >> 20))
echo "Groesse: ${mbytes} MB (${bytes} Byte)" | tee -a ${tar_log}
echo "" | tee -a ${tar_log}
}
function make_tar_backup() {
tar_file=${root_path}'/'${backup_path}${db_name}'_backup_'${timestamp}'.tgz'
tar_options=${tar_db}' '${tar_config}' '${backup_include}
echo ""
echo "TAR-Backup: ${tar_file}" | tee -a ${tar_log}
echo "Include : ${tar_options}" | tee -a ${tar_log}
echo "" | tee -a ${tar_log}
tar -cvzf ${tar_file} ${tar_options} | tee -a ${tar_log}
rm ${db_file}
bytes=$(du -b ${tar_file} | sed 's/\([0-9]*\)\(.*\)/\1/')
mbytes=$((bytes >> 20))
echo "" | tee -a ${tar_log}
echo "Groesse: ${mbytes} MB (${bytes} Byte)" | tee -a ${tar_log}
echo ""
chmod ${tar_rights} ${tar_file}
chmod ${tar_rights} ${tar_log}
}
clear
cd ${root_path}
get_config_data
database_create_backup
make_tar_backup
Alles anzeigen
in der Zeile mit backup_include kann man per Space Verzeichnisse und Dateien zusätzlich ins Backup aufnehmen
wer will, kann es noch per Crontab ausführen lassen ...
aber das wars dann im Grunde auch schon
Probleme? -- Comments bellow