Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a bash script that runs as a cron to backup files on the server.

#!/bin/bash
FILE=/path/to/backup_$(date +%Y%m%d).tar
tar -cf $FILE /backup/this /and/that /and/someotherfiles
gzip $FILE

When I run the script directly using:

sudo bash ./backup-files.sh

It gzips the file, but last night when the cron ran it left it as a tar. Would the cron have saved a log somewhere that'd point to why this may be the case?

share|improve this question
1  
This is not Ubuntu specific, please move it to superuser.com –  David Siegel Jul 29 '10 at 8:51
    
Half the questions on here aren't Ubuntu specific, but from Ubuntu users. If this is supposed to be a help resource to replace/assist the forums, I don't know that we want to head this route already. –  Rick Sep 2 '10 at 12:41
    
This is a pefectly fine question on an Ubuntu computer –  txwikinger Sep 4 '10 at 17:24
    
If the user is on Ubuntu, it perfectly validates being here. This place gives so much of a warm feeling :) –  Ashfame Feb 27 '11 at 14:51

3 Answers 3

up vote 5 down vote accepted

Is the partition where backup is located at its limits?

Your script has created the tarball, but gzip didn't have any space left to compress it.

(you can combine both commands with -z flag for tar)

Woops, I forgot one thing: add -v flag to your tar command. It will display what it does.

share|improve this answer
    
There's plenty of HDD space available. I'll try removing the gzip line and adding the -z flag though, thanks. –  bcmcfc Jul 29 '10 at 8:49

As Pierre has mentioned, you may want to use the -z flag. Generally, I always use tar zcvfP for backing up entire directories and preserving their structure and permissions. The v flag is there too, also useful.

share|improve this answer

If it happens again that your script doesn't do what you want, you can add set -x on top of your script. It will output exactly what it does and this output is often helpful to find bugs. If you call it as a cronjob make sure that $EMAIL is set appropriate.

share|improve this answer

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.