homepage Welcome to WebmasterWorld Guest from 54.196.199.118
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
question about cron job - backup more than one folder
question about cron job - backup more than one folder
drooh




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

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?

 

mcavic




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

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.

drooh




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

simple as that! thanks

drooh




msg:3797287
 6:22 am on Dec 1, 2008 (gmt 0)

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/

mcavic




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

Yep, try:

tar -c -X badfiles *

drooh




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

would that be

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

drooh




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

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

tar -c -X badfiles morebadfiles *

?

mcavic




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

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.

drooh




msg:3797932
 2:24 am on Dec 2, 2008 (gmt 0)

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 ?

mcavic




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

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

drooh




msg:3797963
 2:57 am on Dec 2, 2008 (gmt 0)

very good to know, are there any other useful options that i should be aware of?

mcavic




msg:3797970
 3:07 am on Dec 2, 2008 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved