How to have files backup emailed automatically?


I would like to add code to the following script that will email me the tar.gz file.

suffix=$(date +%y%m%d)
cd ls --color=never -d /home/srikat/.snapshot/hourly.0|head -n1
tar -zvcf /home/srikat/backups/archives/howtotuts_themebackup.$suffix.tar.gz

Also, am not sure if the 3rd line is required. Can anyone let me know?

Thanks in advance.>How To Tutorials


I created a blog post on what I understood so far:


I’m a bit puzzled as to why you’d use the snapshot functions to obtain the files you want to back up (and not the currently live directories), but you probably have a motivation for that.

ls will not color output in noninteractive shells. Period. You do not need to tell it not to.

The third line is needed since you are using a relative path when specifying what you want backed up. You could include it in the fourth line if you really wanted to, since you really do not need to change the directory for tar to find the files (if you give it an absolute path or just a cleverly crafted relative one).

In any case, mailing attachments works with mutt :

echo “Some preface to your mail” | mutt -s “Subjectline you want in the mail” -a filename

i.e. something like

echo “here’s passwd” | mutt -s “System accounts” -a /etc/passwd

would send the /etc/passwd file to


I actually do want to back up live directory.

Can you kindly correct

Thanks in advance.


So am I to understand you just copied the code from somewhere ? It should be obvious on how to tell tar not to get stuff from the snapshot directory but the live one …

Your way works, it’ll just always be an hour late. Since you are writing a howto on it, you might want to look into understanding the commands you are executing :slight_smile:

In any case, the “quickest” way to do it would be to change the cd line to say cd ~ instead of what is there now. Whether it is the most elegant, I’ll leave up to you :slight_smile:



I did mention at the bottom of my blog post a link to the DreamHost wiki entry from which I took the commands.

I have modified the script a little bit (removed the ‘cd…’ line)
to have

Tested and see that it’s working. Thank You.