-
Notifications
You must be signed in to change notification settings - Fork 173
Added a backup tool to import/export store data #35
base: master
Are you sure you want to change the base?
Conversation
d5fa98f
to
2fea134
Compare
might want to make all your methods with |
import tarfile | ||
import time | ||
|
||
_TABLES = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think there might be a way to initialize this programatically out of the database schema? this seems like a maintenance hell.
Thanks for the submission. Will review this morning. As @gubatron mentioned we want to have consistency on code and as you can see the build failed. Just make sure it passes the pylint checks. They include the naming conventions. |
def _exportDatabaseToCsv(tablesAndColumns): | ||
"""Reads the database for all given tables and stores them as CSV files.""" | ||
dbFile = _getDatabase() | ||
result = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result
looks like an unused variable that you forgot to clean up.
Yeah, I'll run it through pylint to make sure it goes well. Also the return True part makes sense. For the import of tables, does it make sense to do as now where it imports all the CSV files or should it be changed to also take a list of tables as export does? Seems the latter makes more sense when it's part of an API. |
Thanks for this. I will review it this week. |
@PLANKT : Few more questions:
|
I haven't had the time to test it yet, but the one comment I would make is I would put backuptool.py in the db subfolder. |
Regarding indexes and table structure, as mentioned it would be convenient for the backup tool to simply handle states, then it won't matter if the tables change in any way as long as the backup is between compatible versions. I looked into two solutions:
Sqlite's official backup API seems to be missing from the Python sqlite package, there is however a module that I found have been recommended from different sites.
In both scenarios the single table backup functionality would be removed, it makes more sense to backup/restore between states of the whole database, and if single table export is wanted it could be an additional feature for datastore to prevent potential missed bugs when changing table structures. |
q: what happened to the previous backup logic? I remember coding somethign which would basically make a copy of the entire db folder and .tgz it. |
fecd9da
to
ca2e123
Compare
I changed the tool to only include two methods to simplify and do a state backup. Also moved it to db folder. The "backup" locks the database and does a full backup of the OpenBazaar data directory for the user (except the backup folder where it places the backups) and the "restore" restores the backup. |
TEST_TAR = 'test.tar.gz' | ||
TEST_FILE_1 = 'test.txt' | ||
TEST_FILE_2 = TEST_FOLDER + os.sep + 'test2.txt' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8-nitpicking: Please add an extra blank line here, before the class definition.
This is something I'd like to revisit once the database schema is set for this version. Also need to make sure the json contracts get backed up. |
6bf74b9
to
4aac065
Compare
Hi, it has been more than a year since @cpacia's last comment. Should this PR be closed or is there a small chance it could be improved and merged? |
try rebasing and see if this even makes sense anymore. I'd close, this will probably be irrelevant very soon now that the server for OB2 will be made in go |
Added a backup tool in order to import and export data for the OpenBazaar server.
It has four public methods which handles backup/restore of files and export/import of data from the database with connections to the API for the client. All the methods base their work directory from OpenBazaar directory, usually "~/OpenBazaar".
backupFiles takes an output file name/path and archives all the content of the OpenBazaar directory to that file.
exportDatabase takes a list of table names and exports their data as CSV files to "OpenBazaar/backup/" directory. It also takes a boolean flag to remove previous files before generation.
restoreFiles imports the files from the given archive to the OpenBazaar directory, overwriting previous files. It also takes a boolean flag to remove previous CSV files since the importDatabase method imports all CSV files in backup directory.
importDatabase imports all CSV files from backup folder to the table, used to import data. It also takes a boolean flag to replace data instead of appending it.