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

  • Home
  • SEARCH
  • 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 6362921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:58:12+00:00 2026-05-24T23:58:12+00:00

how to write a bash script which will dump a database and restore it.

  • 0

how to write a bash script which will dump a database and restore it. there should be two arguments. first one is the name of db which is going to be dumped and another one is name of the db in which i am going to restore the previously dump data.

  • 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-05-24T23:58:13+00:00Added an answer on May 24, 2026 at 11:58 pm

    I got a python script who take the dump and upload it to s3. I think its better than bash script:

    import datetime
    
    import subprocess, tarfile, os, S3, tempfile
    
    #Mysql
    MYSQL_USER = "xxxx"
    MYSQL_PASS = "xxx"
    MYSQL_DB = "xxxxx"
    MYSQL_HOST = "localhost"
    MYSQL_DUMP = "mysqldump"
    
    AWS_ACCESS_KEY_ID = "xxxxxxxxxxxx"
    AWS_SECRET_ACCESS_KEY = "yyyyyyyyyyyyyyyyyyyy"
    
    BUCKET_NAME = "bucket"
    
    FOLDER = "backup/"
    
    KEEP = 5
    
    EXT_TIME = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%dT%H:%M')
    
    print "start mysqldump..."
    
    proc1 = subprocess.Popen(MYSQL_DUMP + " --no-create-info  -u %s -p%s   -x  --databases  %s" % (MYSQL_USER, MYSQL_PASS, MYSQL_DB), shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
    
    t1 = tempfile.NamedTemporaryFile()
    t1.write(proc1.communicate()[0])
    
    tar = tarfile.open( (os.path.join(os.curdir, MYSQL_DB + "_%s.tar.gz" % (EXT_TIME))), "w|gz")
    
    tar.add(t1.name, MYSQL_DB + "_data.sql")
    t1.close()
    tar.close()
    
    print "uploading to S3..."
    conn = S3.AWSAuthConnection( AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY )
    tardata = open(os.path.join(os.curdir, MYSQL_DB + "_%s.tar.gz" % EXT_TIME) , "rb").read()
    response = conn.put(BUCKET_NAME, FOLDER + MYSQL_DB + "_%s.tar.gz" % EXT_TIME, S3.S3Object(tardata))
    
    if response.http_response.status == 200 :
        print "sucessfully uploaded the archive to Amazon S3"
    else:
        print "Uploading database dump to Amazon S3 is not successful" 
    
    os.remove(os.path.join(os.curdir, MYSQL_DB + "_%s.tar.gz" % (EXT_TIME)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a bash script which will, given the name of a
I'm trying to write a bash script which will behave as a basic interpreter,
I want to write a bash script which takes 2 arguments, a and b
I want to write a bash script which will use a list of all
I'm trying to write a bash script that will process a list of files
I am trying to write a bash or PHP script that will execute a
I am trying to write a simple bash script that will search for files
Hey I try to write a littel bash script. This should copy a dir
I'm trying to write a bash script in which I connect to a samba
I want to write a simple bash script that will act as a wrapper

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.