Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 example@mail.com

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

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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

cd /path/to/parent && tar -cjf - directory | uuencode | mail -s "directory backup on $(date)" address@example.com

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.

share|improve this answer
add comment

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

uuencode fileA.zip fileB.zip | mail -s "My Mail Subject" example@mail.com

another example:

tar cvf - Folder | gzip > my_backup.tar.gz | uuencode my_backup.tar.gz | mail -s "Subject" example@mail.com

another example:

gzip -c somefile.tar | uuencode somefile.tar.gz  | mail -s "My Backup" example@mail.com

You could use mutt aswell:

mutt -a file.tar.gz -s "subject of message" example@mail.com

For a more complete guide click here!

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

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.