LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-02-2012, 04:22 PM   #1
l0pht
Member
 
Registered: Sep 2008
Posts: 79

Rep: Reputation: 1
backup-shellscript


hi friends,
i have a shell script that can backup every mysql database and saved it on a destination folder:
Code:
NOW=$(date +"%d-%m-%Y")
DEST="/home/mysql".${NOW}-$(date +"%T")
# set mysql login info
MUSER="root"         # Username
MPASS=''   # Password
MHOST="localhost"  # Server Name
 
# guess binary names
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"
 
[ ! -d "${DEST}" ] && mkdir -p "${DEST}"
# get all db names
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
 FILE=${DEST}/mysql-${db}.${NOW}-$(date +"%T").gz
 # get around error 
 $MYSQLDUMP --single-transaction -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
done
how can i automated it remove 3 or 4 latest one?
thanks
 
Old 11-03-2012, 11:09 AM   #2
JSkywalker
Member
 
Registered: Aug 2007
Distribution: openSUSE
Posts: 102

Rep: Reputation: 24
Quote:
Originally Posted by l0pht View Post
how can i automated it remove 3 or 4 latest one?
I'm a bit cofused by the question, but i assume:
How can you remove backups which are older than 3 or 4 days?

Quote:
find ${DEST}/mysql-* -mtime +3 -exec echo {} \;
If above statements returns a list of the files you want to delete, than change 'echo' to 'rm'.....
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux shellscript Micky12345 Linux - General 1 02-27-2012 11:34 PM
Help Shellscript paraiso Linux - Newbie 7 05-12-2005 07:25 AM
Lockscreen Shellscript 2 paraiso Linux - General 1 05-11-2005 05:30 PM
shellScript help paraiso Linux - Newbie 2 05-10-2005 07:09 PM
ShellScript sharadgana Programming 1 12-16-2004 01:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration