This script's intended use is to be run as a cron or called via command line to quickly back up your forum's database, but, I also added a parameter to have it prompt you for your database information. Anyhow, it saves the database in the format database_name_yyyy-mm-dd_hh-mm-ss.sql.gz , because I sometimes have more than one backup from the same day, and having time helps with that.
I use this on Debian Squeeze Linux, so, that is its intended platform. If you have a different platform, and it's not working right, feel free to provide me with the error and the OS. My Linux knowledge is limited to CentOS, Debian, and Ubuntu, though, so, I may not be able to help you myself.
To set it up, put it wherever you want it, and grant it execution permissions. You may do so with something like this:
chmod u+x ./xf_backup.sh
chmod 700 ./xf_backup.sh
Here's what it can do:
Running it without a parameter just outputs this:
XenForo Backup Script - by Mopquill To run this script, choose one of the parameters: ./xf_backup.sh backup - to automatically back up using config ./xf_backup.sh backup-shell - to have script prompt you for database info
If the times are coming out wrong, either your timezone is not properly set, or your server time is incorrect! To set your timezone, just fill it in in the config area. You can use stuff like US/Eastern, UTC, etc.
I don't want to type all the timezones out, so, you can see all the timezones by running:
The paths for mysqldump and gzip should be detected automatically, but if you don't have them (really just gzip, because if you don't have mysql, you have a very different problem!), you'll either need to ask your host to install them, or if you have shell and the permission to install, you'll want to do one of the following:
Ubuntu, Debian, etc.
apt-get install gzip
CentOS, Fedora, Redhat (all RHEL-based Linuxes), etc.
yum install gzip
Next, you'll want to set it up in a cron, so backups are made automatically, but, that's up to you. From shell, use `crontab -e` to edit your user's cron. Here's what the command I use in mine:
cd /path/to/my/backup/dir && ./xf_backup.sh backup
I'm sure it's not as efficient or elegant as it could be, but it's not terribly complicated, and it works well. I've zipped it to save XenForo an eensy bit of space since it's plaintext. It should still be Linux-encoded (LF only), so you shouldn't have to worry about dos2unixing it or anything.
I will be providing support for this in a limited sort of way. If you're getting errors on certain distros or something (I'm on Debian Squeeze), or if you want features added, or if something isn't working quite ideally, by all means, let me know. However, I'm not looking to teach anyone how to use shell (beyond what's already in this documentation) or write scripts, nor how to resolve dependencies or get things installed right. Basically, if it falls under actually *using* this script and nothing more, I'll try to help as best I can, provided I've got time. If it's something that falls under your duties as administrator, please don't expect much from me.
Having said that, I'm pretty nice, I'll try to help with what I can, within reason.
I'm also most definitely open to suggestions/improved code. Either way, let me know what you think. =]
Disclaimer: This script is provided with the hope that it will be useful, but there are no guarantees nor any warranty whatsoever, expressed or implied, including but not limited to implied warranties of merchantability and fitness for a particular use or purpose. Use of this script is entirely at the risk of its user.
1.0.8 - July 31st, 2012
- Added support for backing up all databases on server with mysql root account, and new mode parameter backup-all-databases
- Optionally backs up data and internal_data directories (suggested by craigiri) with configurable locations -- this is enabled by default, and assumes they are sibling to your library directory
- Added data-only mode parameter to optionally back up just the data directories -- useful for backing up data at different times or in different intervals than your database
- Optionally combines data and internal_data into the same gzipped tar archive -- this avoids a warning from tar regarding parent directories, and is enabled by default
- Optionally creates database backup directory for you if it does not exist -- this is enabled by default
- Now includes --single-transaction in the mysql query (suggested by Coop1979), which should be run much smoother on big boards where you don't want to be locking a bunch of tables
- includes various other stability tweaks to the MySQL commands
- changed inner functioned to be more module-oriented -- this makes the script more efficient
- Various undocumented bug and stability fixes, and feature additions -- sorry, I wasn't keeping track yet.
- Initial Release in Add-on Releases board, undocumented features -- sorry once again.
Likes: gordy and faeronsayn