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

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?

  • 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

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.

  • 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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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