Skip to content

Commit

Permalink
new functionality
Browse files Browse the repository at this point in the history
backup now stores metadata and data in json file. github push functionality is being worked on. there is time zone in the config and a time module
  • Loading branch information
Zbuddy13 committed Sep 6, 2024
1 parent d73e2ae commit 5ca6bca
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
8 changes: 4 additions & 4 deletions backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def main():
# Loop throught tables and take snapshot
for name in tables:
f = open(str(name+".json"), "w")
tableContents = json.dumps(pg.dumpTable(dbOBJ, name), indent=4)
print("Contents to be written to file" + str(tableContents))
combineTables = pg.dumpMetadata(dbOBJ, name) | pg.dumpTable(dbOBJ, name)
tableContents = json.dumps(combineTables, indent=4)
f.write(tableContents)
f.close()
dbOBJ.close()
Expand All @@ -46,8 +46,8 @@ def test():
print(row)

if __name__ == "__main__":
#main()
test()
main()
#test()
if post["backup_interval"] > 0:
mainTimer = timer.initializeTimer()
timer.addJob(mainTimer, main, post["backup_interval"])
Expand Down
2 changes: 2 additions & 0 deletions modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def importConfig(filename):
conf["databases"][database]["backup_count"] = -1
if not conf["databases"][database].get("backup_location", None):
conf["databases"][database]["backup_location"] = str(os.getcwd())+"/Backups"
if not conf["databases"][database].get("tz", None):
conf["databases"][database]["tz"] = 'America/New_York'
else:
print("databases Keyword is necessary to add a database")
return conf
Expand Down
11 changes: 11 additions & 0 deletions modules/github.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os
from git import Repo
import modules.config as config

# Gives the location of the YAML Configuration File
location = os.environ.get("config", "config.yaml")
# Set yaml config as conf
conf = config.importConfig(location)

def setDir(location):
repo = Repo(location)
4 changes: 2 additions & 2 deletions modules/schemas/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ def removeUnwantedTables(tableList, unwantedList):
def dumpTable(dbObject, tableName : str):
with dbObject.cursor(row_factory=psycopg.rows.dict_row) as cur:
cur.execute(f"Select * FROM \"{tableName}\"")
return {tableName: cur.fetchall()}
return {"Data": cur.fetchall()}

# Dumps a single Postgres table
def dumpMetadata(dbObject, tableName : str):
with dbObject.cursor(row_factory=psycopg.rows.dict_row) as cur:
cur.execute(f"SELECT column_name, data_type FROM information_schema.columns WHERE table_schema = 'public' AND table_name = \'{tableName}\';")
return cur.fetchall()
return {"Metadata": cur.fetchall()}

17 changes: 17 additions & 0 deletions modules/time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import time
from datetime import date
import os
import modules.config as config

# Gives the location of the YAML Configuration File
location = os.environ.get("config", "config.yaml")
# Set yaml config as conf
conf = config.importConfig(location)

os.environ['TZ'] = conf["databases"]["postgres"]["tz"]

def getTime():
now = time.localtime()
current_time = time.strftime("%H:%M:%S", now)
currentDateTime = str(date.today()) + " " + str(current_time) # Todays Date
return currentDateTime

0 comments on commit 5ca6bca

Please sign in to comment.