4

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?

4
  • 1
    This is not Ubuntu specific, please move it to superuser.com Jul 29, 2010 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, 2010 at 12:41
  • This is a pefectly fine question on an Ubuntu computer
    – txwikinger
    Sep 4, 2010 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, 2011 at 14:51

3 Answers 3

6

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.

1
  • There's plenty of HDD space available. I'll try removing the gzip line and adding the -z flag though, thanks.
    – bcmcfc
    Jul 29, 2010 at 8:49
6

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.

3

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .