Last active
August 21, 2022 12:17
-
-
Save h3xagn/96e58b02db118616f22aed745d942544 to your computer and use it in GitHub Desktop.
Extract data from SQL Server: https://h3xagn.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get list of history DBs | |
# note: check permission of the user to access 'master' database | |
query = "set nocount on; print 'Database';select name from sys.Databases where name like 'History%'" | |
sqlcmd = f'sqlcmd -S {server} -d ProcessDataDB -U {username} -P {password} -Q "{query}" -s "," -h -1 -W -o "./data/{site}_dbs.csv"' | |
logger.info("-- Getting ProcessDataDB History databases...") | |
os.system(sqlcmd) | |
# get list of historic databases | |
df = pd.read_csv(f"./data/{site}_dbs.csv") | |
logger.info(f"Found {len(df.index)} history DBs.\n") | |
# create list of DBs | |
list_of_dbs = list(df.Database) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment