备份 Wiki 并上传至网盘
跳到导航
跳到搜索
写了个脚本来备份这个 Wiki ,并且自动上传到 Yandex.Disk 。此脚本八成不适合你的需求,请跟据自己的情况修改,这里仅限参考。
1 #!/bin/bash
2
3 # Backup phase
4 wiki_name=fymwiki
5 tmp_dir=$(mktemp --tmpdir -d backup_fymwiki.XXXXXXX)
6 wiki_dir=/srv/wiki
7 lock_warning="苟利国家生死以,岂因祸福趋避之。此 Wiki 正在备份中,请稍等一会儿。"
8
9 echo $lock_warning > $wiki_dir/maintenance.txt
10
11 echo "Dumping database..."
12 db_password=$(echo "<?php $(grep ^\$wgDBpassword $wiki_dir/LocalSettings.php) echo \$wgDBpassword; ?>" | php)
13 mysqldump --user=root --password=$db_password --default-character-set=binary $wiki_name | gzip > $tmp_dir/wiki_backup.sql.gz
14
15 echo "Archiving files..."
16 tar achf $tmp_dir/wiki_backup.tar.gz $wiki_dir
17
18 rm $wiki_dir/maintenance.txt
19
20 # Upload phase
21 url=https://webdav.yandex.ru/Backups/$wiki_name/$(date +%Y%m%d)
22 credential=$(cat credential)
23
24 echo "Uploading to $url ..."
25 curl -i --user $credential -X MKCOL $url
26 curl -i --user $credential -T $tmp_dir/wiki_backup.sql.gz $url/
27 curl -i --user $credential -T $tmp_dir/wiki_backup.tar.gz $url/
28
29 echo "Complete!"
30 rm -r $tmp_dir