Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Trying to set up a cronjob ran tar script to backup site (without .git and setup folder) every night and upload time stamped archive to Dropbox.

It gives me a hard time as archive is created along with everything in it, seems exclude flag doesn't work for some reason now. Maybe it's the zsh's character escape the issue, not sure, still learning. Please help..

#!/bin/zsh

DATE=`date +%d-%m-%Y---%H-%M-%S`
FILE=backup-$DATE.tar.bz2
DROPBOX=/home/pentago/appz/bin/dropbox.py 
TARGET=/home/pentago/public_html/
DESTINATION=/home/pentago/Dropbox/Backups
EXCLUDED={setup,.git*}


tar -cpPf $FILE --exclude=$EXCLUDED $TARGET{*,.*}
share|improve this question

2 Answers 2

There a re a few problems in your script. You need to add the j option to tar in order to create bzip2 files. I believe the exclude commands are ignored because you are explicitly adding all files in your target to tar's imput file list. You don't need $TARGET/* simply $TARGET will do. Finally, the excluded blob is probably being expanded in your current directory, not in the target directory.

Try something like this:

#!/bin/zsh

DATE=`date +%d-%m-%Y---%H-%M-%S`
FILE=backup-$DATE.tar.bz2
DROPBOX=/home/pentago/appz/bin/dropbox.py 
TARGET=/home/pentago/public_html/
DESTINATION=/home/pentago/Dropbox/Backups



tar -cjpPf $FILE --exclude=setup --exclude=.git $TARGET
share|improve this answer
    
nah, it still doesn't exclude .git and setup directories from archive.. :/ –  purpler Feb 19 '13 at 11:04
    
@purpler The real problem is probably that EXCLUDED={setup,.git*} doesn't expand properly. –  slhck Feb 21 '13 at 13:06
    
@slhck wow, great timing, I just figured that out :). Any way to avoid hard coding the excludes? –  terdon Feb 21 '13 at 13:11
    
@purpler it should work now. –  terdon Feb 21 '13 at 13:11
    
Not from my head, no. Have to look up how the brace expansion works, maybe it needs to be evald first? For safety reasons I'd suggest to quote the variables properly. Even if they don't include whitespace, it's probably a good habit to develop. –  slhck Feb 21 '13 at 13:19

You really should be using git-archive for that.

git archive -o $FILE HEAD

to avoid including setup you'll need to set the attribute export-ignore on it. See man gitattributes and man git-archive (loads of examples). Notice that that assumes that setup is checked-in, if not you don't have to do anything.

share|improve this answer
    
ok man but i didn't ask for help with git, rather backup shell script. –  purpler Feb 22 '13 at 16:09
    
Since you were excluding .git dir, I just assumed you were backing up a git repo. –  Francisco Mar 12 '13 at 12:05
    
No, i was trying to backup my shell account files daily to Dropbox, disregard git.. –  purpler Mar 13 '13 at 10:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.