<?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>Naqoosh &#187; script</title>
	<atom:link href="http://www.naqoosh.com/tag/script/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.naqoosh.com</link>
	<description>Software Development, Trekking and Wildlife</description>
	<lastBuildDate>Thu, 05 Jan 2012 10:19: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>
		<item>
		<title>Mysql backup and delete older files</title>
		<link>http://www.naqoosh.com/mysql-db-backup-and-delete-older-files/</link>
		<comments>http://www.naqoosh.com/mysql-db-backup-and-delete-older-files/#comments</comments>
		<pubDate>Fri, 22 May 2009 07:00:25 +0000</pubDate>
		<dc:creator>Meraj Khattak</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[delete]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.naqoosh.com/?p=83</guid>
		<description><![CDATA[We were taking mysql backups using a very simple shell script which was using mysqldump as below. #!/bin/sh #echo "Starting the script"; HOST=localhost USER=myDBUser PASSWD='myPassword'; # create directory if it doesn't exist OLDBACKUP=/home/my_backup/sql_files if [ ! -d "$OLDBACKUP" ]; then &#8230; <a href="http://www.naqoosh.com/mysql-db-backup-and-delete-older-files/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We were taking mysql backups using a very simple shell script which was using <em>mysqldump</em> as below.</p>
<pre name="code" class="python">#!/bin/sh
#echo "Starting the script";
HOST=localhost
USER=myDBUser
PASSWD='myPassword';

# create directory if it doesn't exist
OLDBACKUP=/home/my_backup/sql_files
if [ ! -d "$OLDBACKUP" ]; then
# create direcotry
mkdir /home/my_backup/sql_files
fi

# set file names by appending date to each file
dbName=dbName-`date -I`.sql;

# take db backups
mysqldump -u $USER -p$PASSWD -n -c myDbName &gt;  $dbName;

# move the file to sql_files directory
mv $dbName $OLDBACKUP</pre>
<p>We were keeping old backup files but we knew that we would need to remove the backup files older than two weeks or a month. I was thinking what to do and after some studying I found the following one line, would help us remove files older than x number of days.</p>
<pre name="code" class="python">find /home/my_backup/sql_files -type f -mtime +15 | xargs rm</pre>
<p>Where 15 could be changed to any number of days and it will remove all the files older than that number of days recursively, using this command. This command won&#8217;t delete any special files or sub directories.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.naqoosh.com/mysql-db-backup-and-delete-older-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

