0
class Command(BaseCommand):
  args = 'Arguments is not needed'
  help = 'Django admin custom command poc.'

  def handle(self, *args, **options):
        db_alias = options.get('olddb') 
        db_entry = settings.DATABASES.get(db_alias)
        output = open(output_filename,'w')

        cmd = ["mysqldump",
               "-u", db_entry.get('USER'),
               "-p%s" % db_entry.get('PASSWORD'),
               "-h", db_entry.get('HOST'),
               db_entry.get('NAME')]
        subprocess.call(cmd, stdout=output)

Here I am dumping my database(olddb).Is the syntax is correct or not for dumping or not? I am running a command as "python manage.py sqldump". I have a schema in my current DB.How to migrate the data to a new database? I don't have any idea what is the schema present in new DB. While migrating data if error comes the rollback have to be done in new DB.

Or any other good Article to get more INFO?

1 Answer 1

0

You will find lots of info if you search for mysqldump. For instance:

backup: # mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

restore:# mysql -u root -p[root_password] [database_name] < dumpfilename.sql

comes from: http://www.thegeekstuff.com/2008/09/backup-and-restore-mysql-database-using-mysqldump/

If you look at the dumpfilename.sql you will see it is a bunch of sql commands to create your tables, then insert commands to insert data into them

Sign up to request clarification or add additional context in comments.

3 Comments

Thats great. But how can i check the difference between two schema of two databases?
They will be identical. Take a look at the file that is produced.
No. I am talking about the diff schema before restoring

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.