Welcome to WebmasterWorld Guest from 54.197.199.191

Forum Moderators: bakedjake

question about cron job - backup more than one folder

question about cron job - backup more than one folder

   
5:56 am on Dec 1, 2008 (gmt 0)

5+ Year Member



this is my file domain.sh

#!/bin/bash
suffix=$(date +%y%m%d)
cd /home/your-user-name/
nice -19 tar -c your-domainname-folder/ gzip -c > backups/archives/yourdomainname.com-$suffix.tar.gz

How would I tell it to put a few different domain names in the zip?

For instance my root looks like this

/website1/
/website2/
/website3/
/somefiles/
/otherfiles/

And I only want to zip up website1, 2 and 3 but not the others, how do I write this into my cron?

6:05 am on Dec 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want them all in the same gz file:

tar -c website1 website2 whatever gzip -c > backups/archives/yourdomainname.com-$suffix.tar.gz

If you want them in different files, then just run a separate tar command for each one.

6:20 am on Dec 1, 2008 (gmt 0)

5+ Year Member



simple as that! thanks
6:22 am on Dec 1, 2008 (gmt 0)

5+ Year Member



would there be a way to specify all folders except certain ones?
for instance everything but /badfiles/ ?

This way if files are added to the domain the cron doesnt need to change

/website1/
/website2/
/website3/
/somefiles/
/badfiles/

6:50 am on Dec 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep, try:

tar -c -X badfiles *

6:52 am on Dec 1, 2008 (gmt 0)

5+ Year Member



would that be

tar -c -X badfiles * website1 website2 whatever gzip -c > backups/archives/yourdomainname.com-$suffix.tar.gz

6:53 am on Dec 1, 2008 (gmt 0)

5+ Year Member



what if there were more than one folder you didnt want to include?

tar -c -X badfiles morebadfiles *

?

8:12 am on Dec 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmm, the -X isn't working for me, but this should:

tar -c --exclude badfile1 --exclude badfile2 * ¦ gzip -c > backups/archives/yourdomainname.com-$suffix.tar.gz

The * specifies all files and folders except the ones that were previously excluded. Keep in mind also that "backups" should be excluded, or it should be somewhere else so that it's not included in the backup.
2:24 am on Dec 2, 2008 (gmt 0)

5+ Year Member



that seems to work well with the --exclude

what does the * mean?

and in the previous example I had what does the nice -19 do ?

2:47 am on Dec 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The * specifies all files and folders. Nice 19 sets the backup to a low priority so that it doesn't use too much CPU time. If that's a concern, you'll need it before the gzip too, because gzip will be using most of the CPU time.

nice -19 tar -c --exclude badfile1 --exclude badfile2 * nice -19 gzip -c > backups/archives/yourdomainname.com-$suffix.tar.gz
2:57 am on Dec 2, 2008 (gmt 0)

5+ Year Member



very good to know, are there any other useful options that i should be aware of?
3:07 am on Dec 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To see a list of files on the backup:

gunzip -c backupfile.tar.gz tar tv

To restore a specific file:

gunzip -c backupfile.tar.gz tar xv website1/myfile.html

To restore all files (and replace any existing files without asking):

gunzip -c backupfile.tar.gz tar xv

And if you're low on disk space, and your system has bzip2 installed, you can replace gzip with bzip2, replace gunzip with bunzip2, and replace .gz with .bz2. It'll take longer to run, but the backups should be a little smaller.

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month