-
Notifications
You must be signed in to change notification settings - Fork 283
Backups
Use mysqldump
to export your SQL data, then create a compressed archive of it and all your OneBody files:
-
Dump the database to a sql file:
mysqldump -u root -p onebody > /var/www/onebody/db/onebody.sql
-
Check that the file contains data:
less /var/www/onebody/db/onebody.sql
IMPORTANT: Verify your church's data is in this file.
Press
q
to quit this view. -
Compress the file to save space:
tar czvf ~/onebody_backup_`date +%Y-%m-%d-%H%M`.tgz /var/www/onebody
To do a restore of the SQL database, extract the tgz file, then:
cd /var/www/onebody
bundle exec rake db:create
mysql -u root -p onebody < onebody.sql
If your photo files, attachments, documents, etc. were lost, you also have a copy of them in your backup. Just copy the public/system
contents from your tgz into /var/www/onebody/public/system
.
You can also restore to a different server with OneBody installed! Just make sure the version of OneBody installed is the same or newer than the one that was running when you made the backup.
See the Upgrade by Copying Data page for more help.
Backup is an excellent ruby tool to use for file and database backups of your OneBody installation. Backup is documented thoroughly here and I would urge you to read the documentation to see what features beyond those discussed here are available.
To install Backup, simply install the backup
gem:
sudo gem install backup
The beauty of Backup is the number of different model components
which it provides. For my backup configuration, I want both file and database backups, which are gzipped and encrypted before being stored locally and remotely (S3). I also want to be notified via e-mail if a backup operation fails to succeed.
To create the model file for this desired backup configuration, I simply run:
backup generate:model --trigger onebody --archives --storages='local,s3' --compressor='gzip' --notifiers='mail' --databases='mysql' --encryptor='openssl'
Now, we need to tailor the modeled configuration to suit our environment:
vi Backup/models/onebody.rb
Here are the specific changes I made, however mileage will most likely vary:
- In the
archive
block, I added anarchive.add
for/var/www/onebody/public/system
. This will ensure that at minimum my user uploaded files will be backed up. However, you could back up the entire/var/www/onebody
directory if you prefer. I also commented out the other genericarchive.add
andarchive.exclude
lines that were there by default. - In the
database
block, I added the necessary details for my MySQL configuration. Note that you should either specifydb.socket
ordb.host
anddb.port
. - In the
store_with S3
block, I specified my AWS S3 details. Note that I also added an explicits3.keep = 30
to ensure that old backups are rotated out to keep my AWS S3 bills down. - In the
encrypt_with
block, I updatedencryption.password
with a password to encrypt my backups with. You will need to use this same password to decrypt the backups when needing to do a restore. - Lastly, I updated the
notify_by Mail
block to reflect my specific e-mail configuration. I run Exim on my OneBody server, and as you can see most default lines were removed:
notify_by Mail do |mail|
mail.on_success = false
mail.on_warning = true
mail.on_failure = true
mail.from = "someuser@onebodyserver"
mail.to = "[email protected]"
mail.port = 25
mail.domain = "localhost"
end
(Replace someuser@onebodyserver
and [email protected]
with appropriate From:
and To:
addresses)
Now, go ahead and attempt a manual backup:
backup perform --trigger onebody
The output here should be quite verbose, and it will be quite apparent if any problems were encountered.
Before moving on, I would strongly urge you to try obtaining the backup you just made from S3 and validating that you can restore it in a development environment. There is little point doing anything further if the backups you are making aren't complete and will not get you back up and running with minimal data loss should, for example, your server experience a drive failure.
Assuming the manual backup was successful and you have verified that the backup being sent to S3 is good, you can go ahead and add a cronjob so that backups are taken on a routine schedule. In my environment, I want backups to be taken daily at midnight (00:00).
Firstly, edit your crontab:
crontab -e
Now, add a new line for backups:
0 0 * * * backup perform --trigger onebody
If you see additional crontab entries for other OneBody-related jobs, go ahead and add this new line after the # End Whenever generated tasks for: /var/www/onebody/config/schedule.rb
line. We do not want to interfere with the whenever
crontab configuration for OneBody rails-related jobs.
Again, please refer to the Backup documentation to see the full list of features and options available to use.