+#!/bin/bash
+# if we get an error, keep going but return it at the end
+last_error=0
+trap 'last_error=$?' ERR
+source ~/mw_vars
+# No strict because the host is likely not named the same as
+# the domain.
+ssh="ssh -oStrictHostKeyChecking=no"
+logfile=/var/log/${mwdomain}_backup.log
+{
+echo "#### starting backup at $(date) ####"
+$ssh root@$mwdomain <<ENDSSH
+set -x
+tee -a $mwc<<'EOF'
+\$wgReadOnly = 'Dumping Database, Access will be restored shortly';
+EOF
+mkdir -p ~/wiki_backups
+mysqldump -p$dbpass --default-character-set=binary my_wiki > ~/wiki_backups/wiki_db_backup
+sed -i '\$ d' $mwc # delete read only setting
+ENDSSH
+# add no strict option to the defaults
+
+rdiff() { rdiff-backup --remote-schema "$ssh -C %s rdiff-backup --server" "$@"; }
+set -x
+rdiff root@$mwdomain::/root/wiki_backups ~/backup/${mwdomain}_wiki_db_backup
+rdiff root@$mwdomain::$mw ~/backup/${mwdomain}_wiki_file_backup
+set +x
+echo "=== ending backup at $(date) ===="
+} &>>$logfile
+if [[ $last_error != 0 ]]; then
+ echo "backup for $mwdomain failed. See $logfile"
+fi
+exit $last_error