Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
 Post subject: Back up files to email?
PostPosted: Mon Mar 30, 2009 12:03 pm 
Offline
Senior Newbie

Joined: Wed Feb 04, 2009 6:02 am
Posts: 8
I've got eight sites running on my Linode at the moment. Three are mine and the remaining 5 are for others. I have no current back-up strategy and it's starting to worry me.

All the files are in one /websites directory. Simple enough. And they're all relatively small.

I'd like to recursively zip or tar.gz that dir and immediately fire that file off to my email account (on gmail) once a day.

I can do the zipping. I can do the scheduling. I just can't do the email sending. Any tips there?

I'm also not sure if what I'm planning is a good idea. I think I'd rather have many duplications in my gmail account (I'm allowed 25gigs and easy they're enough to clean up) than various rsync diffs that need a PHD to restore.


Top
   
 Post subject:
PostPosted: Mon Mar 30, 2009 12:15 pm 
Offline
Senior Member

Joined: Thu Dec 04, 2008 10:55 am
Posts: 57
Location: New Jersey
I use this occasionally.. Perhaps it could help you?

http://www.webcheatsheet.com/PHP/send_e ... Attachment

Code:
<?php 
$fileatt = "/path/to/file.zip"; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = "file.zip"; // Filename that will be used for the file as the attachment

$email_from = "webmaster@domain.com"; // Who the email is from
$email_subject = "Subject"; // The Subject of the email
$email_txt = "Message"; // Message that the email has in it

$email_to = "someone@gmail.com"; // Who the email is too

$headers = "From: ".$email_from;

$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);

$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";

$data = chunk_split(base64_encode($data));

$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";

$ok = @mail($email_to, $email_subject, $email_message, $headers);

if($ok) {
echo "<font face=verdana size=2>The file was successfully sent!</font>";
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
?>


Top
   
 Post subject: mutt might work
PostPosted: Mon Mar 30, 2009 12:33 pm 
Offline
Newbie

Joined: Mon Mar 30, 2009 12:31 pm
Posts: 2
I haven't tried this but plan to

#!/bin/bash
tar -zcf /tmp/backup.tar.gz /home/calvin/files
echo | mutt -a /tmp/backup.tar.gz -s “daily backup of data” calvin@cnh.com


Top
   
 Post subject:
PostPosted: Mon Mar 30, 2009 3:26 pm 
Offline
Senior Member
User avatar

Joined: Sat Oct 16, 2004 11:13 am
Posts: 176
or you can use GmailFS.


Top
   
 Post subject:
PostPosted: Mon Mar 30, 2009 7:32 pm 
Offline
Senior Member

Joined: Mon Feb 02, 2009 1:43 am
Posts: 67
Website: http://fukawi2.nl
Location: Melbourne, Australia
This perl script works excellent for me:
http://www.pastebin.ca/1377411

Just save it to /usr/local/bin/sendEmail and make it executable. It will give you usage if you run it without arguments.


Top
   
 Post subject:
PostPosted: Tue Mar 31, 2009 11:09 am 
Offline
Senior Newbie

Joined: Wed Feb 04, 2009 6:02 am
Posts: 8
Thanks for all the suggestions. I'm going to have a stern look at them all after work.

I think I won't be doing the GmailFS route for one main reason: I don't really want my server being able to access my Gmail. That's one of the main reasons I don't host my own email on my VPS; I don't want my entire life rooted if one of my VPSs does.


Top
   
 Post subject:
PostPosted: Tue Mar 31, 2009 12:33 pm 
Offline
Senior Newbie

Joined: Wed Feb 04, 2009 6:02 am
Posts: 8
Right. I've been dicking around with mutt and kept running into maximum attachment issues.

The fool would edit his config. I fixed the attachment.

Here's the command I'm firing off:

Code:
rm sites.7z && 
7z a -t7z -m0=lzma -mx=9 -xr@ex sites.7z /websites &&
echo | mutt -a sites.7z -s "VPS Backup" me@email-address.com


And I've got a file called ex that ignores things I couldn't care less about losing (for fairly obvious reasons):
Code:
.bzr
.svn
.git
*.pyc
amedia
logs
*.log


Using 7z over gzip made a 60% difference, getting the attachment well under the sendmail barrier.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group