fixes
[distro-setup] / machine_specific / kd / filesystem / etc / cron.daily / mediawiki_backup
1 #!/bin/bash
2 # if we get an error, keep going but return it at the end
3 last_error=0
4 trap 'last_error=$?' ERR
5 source ~/mw_vars
6 # No strict because the host is likely not named the same as
7 # the domain.
8 ssh="ssh -oStrictHostKeyChecking=no"
9 logfile=/var/log/${mwdomain}_backup.log
10 {
11 echo "#### starting backup at $(date) ####"
12 $ssh root@$mwdomain <<ENDSSH
13 set -x
14 tee -a $mwc<<'EOF'
15 \$wgReadOnly = 'Dumping Database, Access will be restored shortly';
16 EOF
17 mkdir -p ~/wiki_backups
18 mysqldump -p$dbpass --default-character-set=binary my_wiki > ~/wiki_backups/wiki_db_backup
19 sed -i '\$ d' $mwc # delete read only setting
20 ENDSSH
21 # add no strict option to the defaults
22
23 rdiff() { rdiff-backup --remote-schema "$ssh -C %s rdiff-backup --server" "$@"; }
24 set -x
25 rdiff root@$mwdomain::/root/wiki_backups ~/backup/${mwdomain}_wiki_db_backup
26 rdiff root@$mwdomain::$mw ~/backup/${mwdomain}_wiki_file_backup
27 set +x
28 echo "=== ending backup at $(date) ===="
29 } &>>$logfile
30 if [[ $last_error != 0 ]]; then
31 echo "backup for $mwdomain failed. See $logfile"
32 fi
33 exit $last_error