LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-24-2009, 08:51 PM   #1
goltoof
LQ Newbie
 
Registered: Sep 2009
Posts: 7

Rep: Reputation: 0
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.
 
Old 10-24-2009, 10:51 PM   #2
nilleso
Member
 
Registered: Nov 2004
Location: ON, CANADA
Distribution: ubuntu, RHAS, and other unmentionables
Posts: 372

Rep: Reputation: 31
first get your backup working then worry about adding it to cron. try something like this:
Quote:
tar --exclude=/mydir/sitedir/trash --exclude=/mydir/sitedir/mp3 -cvpzf /whereever/mysitedir.tgz /mydir/sitedir
this will backup all of /mydir/sitedir minus the trash and mp3 directories to a gzip-compressed tar file
then add the working command to croncron:
Quote:
1 1 * * * /usr/bin/bash -lc "placeentirecommandabovehere"

Last edited by nilleso; 10-25-2009 at 10:19 AM.
 
Old 10-25-2009, 03:04 AM   #3
goltoof
LQ Newbie
 
Registered: Sep 2009
Posts: 7

Original Poster
Rep: Reputation: 0
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.
 
Old 10-25-2009, 10:21 AM   #4
nilleso
Member
 
Registered: Nov 2004
Location: ON, CANADA
Distribution: ubuntu, RHAS, and other unmentionables
Posts: 372

Rep: Reputation: 31
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
 
Old 10-25-2009, 01:48 PM   #5
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
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
 
Old 10-25-2009, 07:19 PM   #6
goltoof
LQ Newbie
 
Registered: Sep 2009
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by nilleso View Post
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
It is homework... assigned by a catastrophic website failure causing me a lot of lost work

daily backup
Code:
* 0 * * * /usr/bin/bash tar --exclude=/web/webdir/images -cvpzf /backups/daily/site_`date +%Y%m%d_%H`.tgz /web/webdir
monthly backup
Code:
* * 1 * * /usr/bin/bash tar --exclude=/web/webdir/images -cvpzf /backups/monthly/site_`date +%Y%m%d_%H`.tgz /web/webdir
remove old files
Code:
* 0 * * * /usr/bin/bash find /backups/daily -mtime +30 -exec rm -f {} \;
now if I were only kinky enough to turn it into a single script instead of relying on multiple crons :P Thanks for you help!

Last edited by goltoof; 10-25-2009 at 07:55 PM.
 
Old 10-25-2009, 08:22 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
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'.
 
Old 10-25-2009, 11:48 PM   #8
goltoof
LQ Newbie
 
Registered: Sep 2009
Posts: 7

Original Poster
Rep: Reputation: 0
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.

Last edited by goltoof; 10-25-2009 at 11:50 PM.
 
Old 10-27-2009, 01:22 PM   #9
Davvvvid
LQ Newbie
 
Registered: Nov 2008
Posts: 6

Rep: Reputation: 0
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

Last edited by Davvvvid; 10-27-2009 at 01:30 PM.
 
Old 10-27-2009, 03:40 PM   #10
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Looking at the man page for cron, the syntax is:
  1. Minute
  2. Hour
  3. Day of Month
  4. Month
  5. Day of Week
  6. Command

Code:
* 0 * * * /usr/bin/bash tar --exclude=/web/webdir/images -cvpzf /backups/daily/site_`date +%Y%m%d_%H`.tgz /web/webdir
In this example, the script would run every minute from 0:00 to 0:59!

Likewise your Monthly script would run every minute of the day!

I am assuming that this is not what you are intending...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Plesk Cron Backup Script Sureshan Linux - Newbie 4 07-16-2009 05:44 AM
Create a backup cron script brokenhalo Linux - Newbie 15 09-27-2008 11:44 AM
Cron backup script stops running after a few days brokenpromises Linux - Server 5 04-05-2008 05:30 AM
i want to cron a backup script sneakyimp Linux - Software 4 03-25-2008 09:02 PM
Backup script won't run in cron job. Why? Micro420 Linux - General 19 10-31-2007 08:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration