One of great things with stuff being files is that you can simply copy and move them around.
Taking this fact to my advantage, here’s a simple backup system I wrote for my SQLite databases – it’s just a one-liner shell-script inside an fcronjob 1 – and pretty self-explanatory, I hope:
# Backup SQLite
%daily,nice(7),random,mail(no) * 04-05 cp -p /path/to/htdocs/data/owncloud.db /backup/owncloud/$(date +%Y-%m-%d)_ownloud.db
%daily,nice(7),random,mail(no) * 04-05 cp -p /path/to/htdocs/user/habari.db /backup/habari/$(date +%Y-%m-%d)_habari.db
# Clean backup
%monthly,nice(7),mail * * * rm /backup/habari/$(date -d "2 months ago" "+%Y-%m")-??.habari.db
%monthly,nice(7),mail * * * rm /backup/owncloud/$(date -d "2 months ago" "+%Y-%m")-??.owncloud.db
The cleaning bit has a failsafe. When I make an important backup (e.g. by hand before messing with something), I append a note to the filename. And the script only deletes files that end with the database name.
For example, if this is the satate of your backups at the moment:
/backup/habari:
2012-09-20_habari.db_first_post
2012-09-21_habari.db_faled_migration
2012-09-23_habari.db_pre-deletion_of_MarkUp
2012-09-24_habari.db_pre-migration_from_Drupal
2012-09-25_habari.db
2012-09-25_habari.db_post-successful_migration_from_Drupal
2012-09-25_habari.db_post-successful_migration_to_matija.suklje.name
2012-09-25_habari.db_pre_migration_to_matija.suklje.name
2012-09-26_habari.db
2012-09-27_habari.db
2012-09-28_habari.db
2012-09-29_habari.db
2012-09-29_habari.db_post_markup_and_link_cleanup
2012-09-29_habari.db_post_markup_link_and_logs_cleanup
/backup/owncloud:
2012-09-20_owncloud.db
2012-09-25_ownloud.db_just_a_failsafe_backup
2012-09-26_ownloud.db
2012-09-27_ownloud.db
2012-09-28_ownloud.db
2012-09-29_ownloud.db
…after the cleaning, you would still be left with:
/backup/habari:
2012-09-20_habari.db_first_post
2012-09-21_habari.db_faled_migration
2012-09-23_habari.db_pre-deletion_of_MarkUp
2012-09-24_habari.db_pre-migration_from_Drupal
2012-09-25_habari.db_post-successful_migration_from_Drupal
2012-09-25_habari.db_post-successful_migration_to_matija.suklje.name
2012-09-25_habari.db_pre_migration_to_matija.suklje.name
2012-09-29_habari.db_post_markup_and_link_cleanup
2012-09-29_habari.db_post_markup_link_and_logs_cleanup
/backup/owncloud
2012-09-25_ownloud.db_just_a_failsafe_backup
…quite a simple overview, isn’t it? ☺
hook out → wow, I haven’t done so much admining in aaaageeeeeees …feels good :3
Update 0: Added an actual example.
Update 1: In light of a wider backup plan, I migrated to RSnapshot. I can warmly recommend it.
-
Sure, the same could be done in any Cron, but I prefer FCron. ↩