<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tesna.net &#187; Linux</title>
	<atom:link href="http://tesna.net/tag/linux/feed" rel="self" type="application/rss+xml" />
	<link>http://tesna.net</link>
	<description>Just some random thoughts of me</description>
	<lastBuildDate>Tue, 02 Mar 2010 08:28:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to automatically backup a directory and FTP/email it using script and cron</title>
		<link>http://tesna.net/2008/12/18/how-to-automatically-backup-a-directory-and-ftp-email-using-script-and-cron</link>
		<comments>http://tesna.net/2008/12/18/how-to-automatically-backup-a-directory-and-ftp-email-using-script-and-cron#comments</comments>
		<pubDate>Thu, 18 Dec 2008 00:00:13 +0000</pubDate>
		<dc:creator>Tesna</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[email]]></category>

		<guid isPermaLink="false">http://tesna.net/?p=146</guid>
		<description><![CDATA[I was looking a simple way to automatically backup my files on the server then automatically sends them to designated email address. Since I have quite limited storage space on my server, then sending it to one of my email account hosted on Google Apps it would be almost ideal for storage backups since Google [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">I was looking a simple way to automatically backup my files on the server then automatically sends them to designated email address. Since I have quite limited storage space on my server, then sending it to one of my email account hosted on Google Apps it would be almost ideal for storage backups since Google Apps email account has large storage space (7GB).</p>
<p><span id="more-146"></span></p>
<p style="text-align: justify;">After some googling, I found a bash script on <a title="Ameir Abdeldayem" href="http://www.ameir.net" target="_blank">ameir.net</a>, which I thought it would be perfect for the job. But unfortunately gmail refused to receive the backups emails since its larger than 20MB/message. Then I modified the script to allow the backup files compressed using tar.gz format (previously its using .zip format), automatically splitting them every 15MB, and finally sends each individual attachment. Just put the code somewhere in your server, then configure cron to execute it how often you want your files to be backed up.</p>
<p style="text-align: justify;">PS: on ameir.net I&#8217;ve also found a <a href="http://www.ameir.net/blog/index.php?/archives/18-MySQL-Backup-to-FTP-and-Email-Shell-Script-for-Cron-v2.1.html" target="_blank">script</a> to dump mysql database and sends them to email. You should check out the website.</p>
<pre lang="bash">
#! /bin/bash# Ameir Abdeldayem# http://www.ameir.net# You are free to modify and distribute this code,# so long as you keep my name and URL in it.
# Last modified: August 1, 2006
#-------------------------------------------------------------
# your server's name
SERVER=servername.yourdomain.com
# directory to backup to
BACKDIR=~/backups
# date format that is appended to filename
DATE=`date +'%m-%d-%Y'`
# directories to backup, separated by a space
# if this script is a level above a directory you want to backup,
# you can simply enter its name, otherwise, type the absolute path,
# with or without a trailing slash.
DIRS="/your/directory/"
# set to 'y' if you want to backup all your folders. this will backup
# all files and folders in the script's parent directory
BACKALL=n
#----------------------Mail Settings--------------------#
# set to 'y' if you'd like to be emailed the backup (requires mutt)
MAIL=y
# email addresses to send backups to, separated by a space
EMAILS="youremail@yordomain.com"
# email subject
SUBJECT="Directory Backup on $SERVER ($DATE)"
#----------------------FTP Settings--------------------#
# set "FTP=y" if you want to enable FTP backups
FTP=n
# FTP server settings; should be self-explanatory
FTPHOST="ftp.server.com"
FTPUSER="user"
FTPPASS="password"
# directory to backup to. if it doesn't exist, file will be uploaded to
# first logged-in directory
FTPDIR="backups"
#-------------------Deletion Settings-------------------#
# delete old files?
DELETE=y
# how many days of backups do you want to keep?
DAYS=3
#----------------------End of Settings------------------#
# check of the backup directory exists
# if not, create it
if [ -e $BACKDIR ]
then
echo Backups directory already exists
else
mkdir $BACKDIR
fi
# This is a list of folders to be backed up.
# You can add more entries if you want more
# directories to be backed up. The ${PWD##*/}
# from the first entry gets the base name from
# the current directory and uses it in the filename.
# Format: zip -9 -r (where to save) (what to backup).
# Be sure to include $BACKDIR/ in the beginning
# so that the file is saved in the backup directory.
if [ $BACKALL = "y" ]
then
echo Backing up entire parent directory...
tar cfz $BACKDIR/${PWD##*/}-backup-$SERVER-$DATE.zip ./
else
echo Backing up selected directories...
for directory in $DIRS
do
DIR=`echo $directory | sed -e 's/^\///g' -e 's/\/$//g' -e 's/~//g' -e 's/\.//g' -e 's/home\///g' -e 's/\//_/g'`
echo Backing up folder named $directory as $DIR...
tar cfz $BACKDIR/$DIR-backup-$SERVER-$DATE.tar.gz $directory
split -b 15m $BACKDIR/$DIR-backup-$SERVER-$DATE.tar.gz $BACKDIR/$DIR-backup-$SERVER-$DATE.tar.gz
done
fi
if [ $MAIL = "y" ]
then
BODY="Your backup is ready!"
ATTACH=`for filea in $BACKDIR/*$DATE.tar.gzaa; do echo -n "-a ${filea} "; done`
echo $BODY | mutt -s "$SUBJECT" $ATTACH $EMAILS
echo "Your backup part 1 has been emailed to you!"
ATTACH2=`for fileb in $BACKDIR/*$DATE.tar.gzab; do echo -n "-a ${fileb} "; done`
echo $BODY | mutt -s "$SUBJECT" $ATTACH2 $EMAILS
echo "Your backup part 2 has been emailed to you!"
ATTACH3=`for filec in $BACKDIR/*$DATE.tar.gzac; do echo -n "-a ${filec} "; done`
echo $BODY | mutt -s "$SUBJECT" $ATTACH3 $EMAILS
echo "Your backup part 3 has been emailed to you!"
ATTACH4=`for filed in $BACKDIR/*$DATE.tar.gzad; do echo -n "-a ${filed} "; done`
echo $BODY | mutt -s "$SUBJECT" $ATTACH4 $EMAILS
echo "Your backup part 4 has been emailed to you!"
fi
if [ $FTP = "y" ]
then
cd $BACKDIR
ATTACH=`for file in *$DATE.tar.gz; do echo -n -e "put ${file}\n"; done`
ftp -nv <open $FTPHOST
user $FTPUSER $FTPPASS
cd $FTPDIR
$ATTACH
quit
EOF
fi
if [ $DELETE = "y" ]
then
find $BACKDIR -name "*.tar.gz*" -mtime $DAYS -exec rm {} \;
if [ $DAYS = "1" ]
then
echo "Yesterday's backup has been deleted"
else
echo "The backup from $DAYS days ago has been deleted"
fi
fi
echo Your backup is complete!
</pre>
<p></open></pre>
]]></content:encoded>
			<wfw:commentRss>http://tesna.net/2008/12/18/how-to-automatically-backup-a-directory-and-ftp-email-using-script-and-cron/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
