Backups of the live site (moved): Difference between revisions

imported>Paulproteus
imported>Paulproteus
Line 15:
We use this script to run backups. It runs via root's crontab, and emails the results to Asheesh daily.
 
* do_backup.sh: [https://github.com/openhatch/oh-restore/blob/master/do_backup.sh in git]
<pre>
#!/bin/bash
 
set -e
set -x
 
MODE="incr"
DAY_OF_WEEK_AS_NUMBER="$(date +%u)"
if [ "$DAY_OF_WEEK_AS_NUMBER" -eq 6 ] ; then
MODE="full"
fi
 
### Prepare mysql snapshots
for db in $(find /var/lib/mysql/ -mindepth 1 -maxdepth 1 -type d | sed 's,/var/lib/mysql/,,')
do
mysqldump -uroot --single-transaction -p"$(cat /root/passwords/mysql-root-password)" "$db" | gzip | sponge /var/backups/mysql/"$db".sql.gz
done
 
function do_backup() {
TARGET="backups/linode.openhatch.org/$1"
LOCAL_PATH="$2"
ssh rsync.net mkdir -p "$TARGET"
duplicity $MODE --exclude /tmp --exclude /var/lib/mysql --exclude /usr/share/locale --exclude /usr/share/doc --exclude /var/tmp --exclude /var/cache --exclude-other-filesystems --encrypt-key="A5CC321E" "$LOCAL_PATH" scp://rsync.net/"$TARGET"
}
 
do_backup "all" "/"
</pre>
 
== Restoring ==
Anonymous user