Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8512165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:12:25+00:00 2026-06-11T04:12:25+00:00

Following shell script for storing back up of laste 10 database. but there is

  • 0

Following shell script for storing back up of laste 10 database.
but there is small problem.
the script create *.zip file of each data base with date and time and stored in backup folder.
so if i have 4 data base so it will create 4 zip file. And for laste 10 days back up, that mean total i have 40 data base back up.

I want to store the back up of database in last 10 days with seperate folder. so that each folder contain the back up of database.

Following is the shell script.

MHOST=localhost
MUSER=backup
MPASS=SECRET
BACKUPDIR="/mnt/backup"

MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"

DBPREFIX="$(hostname -s).mysqldb"

echo "Run MySQL backup"
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
    FILE=${BACKUPDIR}/${DBPREFIX}.${db}.`date +%Y%m%d`.gz
    $MYSQLDUMP --no-tablespaces --skip-lock-tables -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
done 

find  -name "${BACKUPDIR}/${DBPREFIX}*" -type f -mtime +10 -exec rm -f '{}' ';'  

I am new to the Linux environment.

Please help me on the same

Best Regards
Arvind Porlekar

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:12:27+00:00Added an answer on June 11, 2026 at 4:12 am
    MHOST=localhost
    MUSER=backup
    MPASS=SECRET
    BACKUPDIR="/mnt/backup"
    
    MYSQL="$(which mysql)"
    MYSQLDUMP="$(which mysqldump)"
    GZIP="$(which gzip)"
    
    DBPREFIX="$(hostname -s).mysqldb"
    
    # changed
    DATE_FOR_FOLDER=`date +%y%m%d`
    makedir -p "$BACKUPDIR/$DATE_FOR_FOLDER"
    
    echo "Run MySQL backup"
    DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
    for db in $DBS
    do
        # changed
        FILE=${BACKUPDIR}/${DATE_FOR_FOLDER}/${DBPREFIX}.${db}.`date +%Y%m%d`.gz
        $MYSQLDUMP --no-tablespaces --skip-lock-tables -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
    done 
    
    # changed
    find  -name "${BACKUPDIR}" -type d -mtime +10 -exec rm -rf '{}' ';'  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a shell script to simulate the following problem: File
I am wondering is there any way to execute following shell script, which waits
I have a shell script file (run.sh) that contains the following: #!/bin/bash %JAVA_HOME%/bin/java -jar
The following contents are in a file.i use a shell script to call a
I'm trying to create a new launchagent file that will execute a shell script
I have following small shell script. value='testdir/imp' `mkdir -m 755 $value` echo $ the
Problem: The following shell script code does not produce the expected result: # MYSQL,
I'm trying to convert the following unix shell script to windows: for strWorkerDirectory in
I came across this shell script for OSX and I don't understand the following:
Say for example you had a shell script that utilises inotifywait in the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.