1

I am trying to zip up a directory and have the contents emailed to me. How could I do this?

I have a cron setup for mysql backup which ends like:

 | gzip | uuencode public_html_backup.gz | mail [email protected]

Would I be able to perform a similar thing for zipping a directory?

2 Answers 2

1

To back up /path/to/parent/directory, you can use

cd /path/to/parent && tar -cjf - directory | uuencode | mail -s "directory backup on $(date)" [email protected]

This uses bzip2 compression. If you prefer gzip compression (uses less CPU but compresses less), replace -czf by -cjf. If you prefer zip format, replace tar -czf - directory by zip -r - directory.

1

I dont know your entire command but yes it would work, for example:

uuencode fileA.zip fileB.zip | mail -s "My Mail Subject" [email protected]

another example:

tar cvf - Folder | gzip > my_backup.tar.gz | uuencode my_backup.tar.gz | mail -s "Subject" [email protected]

another example:

gzip -c somefile.tar | uuencode somefile.tar.gz  | mail -s "My Backup" [email protected]

You could use mutt aswell:

mutt -a file.tar.gz -s "subject of message" [email protected]

For a more complete guide click here!

3
  • Thank you also for this - I wish I could accept two answers
    – Malachi
    Sep 25, 2010 at 12:23
  • 1
    @Malachi Soord np aslong as you got it working, its all good :)
    – Prix
    Sep 25, 2010 at 12:30
  • It actually took a combo of both your solutions to get what I required
    – Malachi
    Sep 25, 2010 at 13:28

You must log in to answer this question.

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