Backuplösung für Rootserver

From Q
Jump to navigation Jump to search

Konzept

Verzeichnisstruktur

Code: Verzeichnisstruktur
\root
\root\backup
\root\backup\bin     (Verzeichnis der Backupskripte etc)
\root\backup\htdocs  (Verzeichnis htdocs Backup)
\root\backup\mysql   (Verzeichnis MySQL Backup)
\root\backup\system  (Verzeichnis root Backup)

Backup erstellen

MySQL

#!/bin/bash
date=`date -I`

# configuration variables
USERNAME="backupuser"
PASSWORD="password"
DBHOST="localhost"
BACKUPDIR="/root/backups"

OPTS="--opt --allow-keywords --flush-logs --hex-blob --master-data --max_allowed_packet=16M --quote-names"
OPTS_FULLBACKUP="--all-databases --opt --allow-keywords --flush-logs --hex-blob --master-data --max_allowed_packet=16M --quote-names"

# backup each database into an individual file
DBNAMES="`mysql --user=$USERNAME --password=$PASSWORD --host=$DBHOST --batch --skip-column-names -e "show databases"| sed 's/ /%/g'`"
for i in $DBNAMES
do
mysqldump $i --user=$USERNAME --password=$PASSWORD --host=$DBHOST $OPTS | bzip2 -c > $BACKUPDIR/$i-$date.SQL.bz2
done

# backup all databases into one big file
mysqldump --user=$USERNAME --password=$PASSWORD --host=$DBHOST $OPTS_FULLBACKUP | bzip2 -c > $BACKUPDIR/FULLBACKUP-MYSQL-ALL-$date.SQL.bz2


Verschlüsselung

MySQL

File: backup-mysql.sh
#!/bin/bash
date=`date -I`

# configuration variables
USERNAME="backupuser"
PASSWORD="password"
DBHOST="localhost"
BACKUPDIR="/root/backups"

# encryption variables
PGPMAILUSERPUB="backupuser@deltaquadrant.org"

OPTS="--opt --allow-keywords --flush-logs --hex-blob \
        --master-data --max_allowed_packet=16M --quote-names"
OPTS_FULLBACKUP="--all-databases --opt --allow-keywords --flush-logs --hex-blob \
        --master-data --max_allowed_packet=16M --quote-names"

# backup each database into an individual file
DBNAMES="`mysql --user=$USERNAME --password=$PASSWORD --host=$DBHOST \
        --batch --skip-column-names -e "show databases"| sed 's/ /%/g'`"
   for i in $DBNAMES
    do
     mysqldump $i --user=$USERNAME --password=$PASSWORD --host=$DBHOST $OPTS | bzip2 -c | \
        gpg --armor --encrypt --trust-model always \
        --recipient $PGPMAILUSERPUB - > $BACKUPDIR/$i-$date.SQL.bz2.gpg
    done

# backup all databases into one big file
mysqldump --user=$USERNAME --password=$PASSWORD --host=$DBHOST $OPTS_FULLBACKUP | bzip2 -c | \
        gpg --armor --encrypt --trust-model always \
        --recipient $PGPMAILUSERPUB - > $BACKUPDIR/FULLBACKUP-MYSQL-ALL-$date.SQL.bz2.pgp

Cron Jobs

MySQL

Dateiübertragung

Konzept 1

  • ftp

Konzept 2

  • scponly & keyauth