directory backup cron script
What's a good cron script for backing up and zipping a directory of files, or multiple directories with files, to a backup directory on my server, on a daily basis?
I found an easy to use mysql backup script, now I need to backup my site directory, but not all the directories in it. So I need a method in the script to omit certain directories from backing up, ie dirs that contain gigs worth of files. This seems like it should be one of the most common crons to set a server up with but two pages deep in google (and here) I have yet to find anything remotely resembling a solution. |
first get your backup working then worry about adding it to cron. try something like this:
Quote:
then add the working command to croncron: Quote:
|
Thanks, works fine except for the "exclude" option gives me invalid "e" token.
In addition to this I got to make it create a new backup for each day (by date), create a monthly permament backup in separate directory, and delete all daily backups that are older than 30 days. |
It's --exclude, not -exclude.
for your additional questions, do you have any ideas on how you're going to do that? this is starting to sound like homework cheers :) |
Hello goltoof,
I'm using flexbackup (http://www.edwinh.org/flexbackup/) which is a perlscript. It has a configurationfile in the /etc-directory and one can define sets of directories to backup and one can do full, differential and incremental backups. Since I'm not running a Linux-server I manage the backups with the anacron-daemon. Markus |
Quote:
daily backup Code:
* 0 * * * /usr/bin/bash tar --exclude=/web/webdir/images -cvpzf /backups/daily/site_`date +%Y%m%d_%H`.tgz /web/webdir Code:
* * 1 * * /usr/bin/bash tar --exclude=/web/webdir/images -cvpzf /backups/monthly/site_`date +%Y%m%d_%H`.tgz /web/webdir Code:
* 0 * * * /usr/bin/bash find /backups/daily -mtime +30 -exec rm -f {} \; |
Here's some good scripting guides
http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ I'd keep the mthly cron entry separate from the daily ones for timing ctrl, but call the one script with a param 'daily' or 'mthly'. |
Last step is to create an automated method to restore the website. In lieu of another catastrophe, instead of having to drop the current sitedir/db, then untar the chosen sitedir/db, inject the db and copy the sitedr all manually... instead have a script that'll backup the current site/db and then drop the current sitedir/db then untar and restore with the sitedir/db backups of a given date, all with one command.
|
You might find these links useful:
http://www.desktoplinux.com/articles/AT2280165098.html http://www.debianhelp.co.uk/schedulejobs.htm I read them and learnt quite a lot :) |
Looking at the man page for cron, the syntax is:
Code:
* 0 * * * /usr/bin/bash tar --exclude=/web/webdir/images -cvpzf /backups/daily/site_`date +%Y%m%d_%H`.tgz /web/webdir Likewise your Monthly script would run every minute of the day! I am assuming that this is not what you are intending... |
All times are GMT -5. The time now is 04:37 AM. |