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?

danny
  • 11
  • 2

1 Answers1

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

joel goldstick
  • 4,393
  • 6
  • 30
  • 46