<?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>gHacks Technology News &#124; Latest Tech News, Software And Tutorials &#187; automated backups</title> <atom:link href="http://www.ghacks.net/tag/automated-backups/feed/" rel="self" type="application/rss+xml" /><link>http://www.ghacks.net</link> <description>A technology news blog covering software, mobile phones, gadgets, security, the Internet and other relevant areas.</description> <lastBuildDate>Sat, 11 Feb 2012 17:32:23 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/> <item><title>Back up your Apache web directory and database with this simple script</title><link>http://www.ghacks.net/2009/01/22/back-up-your-apache-web-directory-and-database-with-this-simple-script/</link> <comments>http://www.ghacks.net/2009/01/22/back-up-your-apache-web-directory-and-database-with-this-simple-script/#comments</comments> <pubDate>Thu, 22 Jan 2009 18:58:34 +0000</pubDate> <dc:creator>Jack Wallen</dc:creator> <category><![CDATA[Advice]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[Open Source]]></category> <category><![CDATA[Tutorials Advanced]]></category> <category><![CDATA[Tutorials Basic]]></category> <category><![CDATA[automated backups]]></category> <category><![CDATA[backup-solution]]></category> <category><![CDATA[backups]]></category> <category><![CDATA[cat]]></category> <category><![CDATA[cron]]></category> <category><![CDATA[date]]></category> <category><![CDATA[LAMP]]></category> <category><![CDATA[tar]]></category> <guid
isPermaLink="false">http://www.ghacks.net/?p=10060</guid> <description><![CDATA[I administer a lot of web sites. And all of these web sites need backup solutions. Since most of those web sites use LAMP servers it only made sense to set up a backup system using the available, included open source tools. It didn&#8217;t take long to create a solid backup system and, with the [...]]]></description> <content:encoded><![CDATA[<p>I administer a lot of web sites. And all of these web sites need backup solutions. Since most of those web sites use LAMP servers it only made sense to set up a backup system using the available, included open source tools. It didn&#8217;t take long to create a solid backup system and, with the help of cron, automate that system so that Apache&#8217;s document root and the website databases were backed up regularly and without user intervention.</p><p>The script made use of the following tools: date, cat, tar, mv, and rm. That&#8217;s it. The script will create backups with the date in the file name and then move the backups to a central location. Without further adieu, let&#8217;s get to the script.</p><p><span
id="more-10060"></span><em>#! /bin/sh</em></p><p><em>TMP=&#8221;/tmp/&#8221;</em></p><p><em>#Format the date in YEAR-MO-DY format<br
/> TODAY=`date +%F`</em></p><p><em># Check to see if there is a lastbackup file in /tmp, if not create it,<br
/> # if so then set LAST equal to $TODAY<br
/> if [ -f /tmp/lastbackup ]; then<br
/> LAST=`cat /tmp/lastbackup`<br
/> else<br
/> LAST=$TODAY<br
/> fi</em></p><p><em># Set the web directory backup name to the following<br
/> WEB_FILENAME=&#8221;inc-&#8221;$TODAY&#8221;-web.tar.gz&#8221;</em></p><p><em># Set database backup name to the following<br
/> DB_FILENAME=&#8221;inc-&#8221;$TODAY&#8221;-db.tar.gz&#8221;</em></p><p><em># this tars up my web directory into web.tar.gz tarball.<br
/> /bin/tar -czf $TMP$WEB_FILENAME &#8211;after-date=$LAST /var/www/html</em></p><p><em># Move the web back to the backup directory<br
/> /bin/mv $TMP$WEB_FILENAME /data</em></p><p><em># Remove web backup file from temp director<br
/> rm $TMP$WEB_FILENAME</em></p><p><em># this tars up my database directory into $TODAY-db.tar.gz tarball.<br
/> /bin/tar -czf $TMP$DB_FILENAME &#8211;after-date=$LAST /var/lib/mysql</em></p><p><em># Move the backup database to the backup directory<br
/> /bin/mv $TMP$DB_FILENAME /data</em></p><p><em># Remove web backup file from temp directory<br
/> rm $TMP$DB_FILENAME<br
/> </em></p><p>What I wanted this to do is create daily backups and move the backups to the <strong>/data</strong> directory on the drive housing the server. These backups will be saved for one month. After the month is completed i have a second script that deletes the months backups prior to running the next backup (so there is always a backup to fall to). How I made use of this script is simple. I save the script (called <strong>backup.sh</strong>) in the root user directory and create a second script called <strong>rm_backups.sh</strong> that looks like this:</p><p><em>#! /bin/sh</em></p><p><em>rm /data/*gz</em></p><p>With these two files in place I create two cron entries. The first cron entry is for running the <strong>backup.sh</strong> script and looks like:</p><p>0 23 * * *     ~/backup.sh</p><p>The second cron entry is for running the <strong>rm_backups.sh</strong> script and looks like:</p><p>0 20 1 * *     ~/rm_backups.sh</p><p>Both of the above cron jobs are created as the root user.</p><p><strong>Final Thoughts</strong></p><p>Naturally this solution could be easily modified (using such tools rsync) to set up an offsite backup solution. What should be obvious is that creating a simple, flexible server backup system on Linux is easy. With the help of a little ingenuity, you can create your own automated backup service.</p> ]]></content:encoded> <wfw:commentRss>http://www.ghacks.net/2009/01/22/back-up-your-apache-web-directory-and-database-with-this-simple-script/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
