Skip to content

Instantly share code, notes, and snippets.

@abubelinha
Forked from trafficinc/dbbackup.py
Last active February 26, 2022 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abubelinha/83e2b86fe02422ff8897bc212f9e28a5 to your computer and use it in GitHub Desktop.
Save abubelinha/83e2b86fe02422ff8897bc212f9e28a5 to your computer and use it in GitHub Desktop.
Python script for taking mysqldump
#!/usr/local/bin/python3
"""
Will backup all the databases listed, will put files in same DIR as script'
To run: $ python dbbackup.py
"""
import configparser
import os
import time
import getpass
HOST='localhost'
PORT='3306'
DB_USER='username'
DB_PASS='password'
databases=['database1','database2','database3']
def get_dump(database):
filestamp = time.strftime('%Y-%m-%d-%I')
# D:/xampp/mysql/bin/mysqldump for xamp windows
os.popen("mysqldump -h %s -P %s -u %s -p%s %s > %s.sql" % (HOST,PORT,DB_USER,DB_PASS,database,database+"_"+filestamp))
print("\n|| Database dumped to "+database+"_"+filestamp+".sql || ")
if __name__=="__main__":
for database in databases:
get_dump(database)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment