Skip to content

Commit

Permalink
final version of backup and restore
Browse files Browse the repository at this point in the history
  • Loading branch information
tillsteinbach committed Oct 20, 2021
1 parent ee487cc commit 16e079c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
## [Unreleased] (Available through Edge Tag)
- No unreleased changes so far

## [0.9.0] - 2021-10-20
### Added
- Possibility to backup and restore the database

## [0.8.2] - 2021-10-19
### Fixed
- Refueling seperated in two parts is now joined into one session
Expand Down Expand Up @@ -158,7 +162,8 @@ This is a complete rewrite of VWsFriend using a self developed API. It drops ioB
## [0.1.0] - 2021-04-22
Initial release to enable "latest" tag on dockerhub

[unreleased]: https://github.com/tillsteinbach/VWsFriend/compare/v0.8.1...HEAD
[unreleased]: https://github.com/tillsteinbach/VWsFriend/compare/v0.9.0...HEAD
[0.9.0]: https://github.com/tillsteinbach/VWsFriend/releases/tag/v0.9.0
[0.8.1]: https://github.com/tillsteinbach/VWsFriend/releases/tag/v0.8.1
[0.8.0]: https://github.com/tillsteinbach/VWsFriend/releases/tag/v0.8.0
[0.7.1]: https://github.com/tillsteinbach/VWsFriend/releases/tag/v0.7.1
Expand Down
6 changes: 3 additions & 3 deletions vwsfriend/vwsfriend/agent_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def __init__(self, weConnect, dbUrl, interval, withDB=False, withABRP=False, con
self.agents = {}

if withDB:
if os.path.isfile(configDir + '/' + 'restore.vwsfriendbackup'):
if os.path.isfile(configDir + '/provisioning/database.vwsfrienddbbackup'):
try:
with open(configDir + '/' + 'restore.vwsfriendbackup', mode='rb') as file:
with open(configDir + '/provisioning/database.vwsfrienddbbackup', mode='rb') as file:
LOG.info('Trying to restore database backup')
process = subprocess.run(['pg_restore', '--clean', '--if-exists', '--format', 'c', '--dbname', dbUrl], stdin=file, # nosec
stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False)
Expand All @@ -44,7 +44,7 @@ def __init__(self, weConnect, dbUrl, interval, withDB=False, withABRP=False, con
else:
LOG.info('It looks like the backup could be successfully restored')
finally:
os.remove(configDir + '/' + 'restore.vwsfriendbackup')
os.remove(configDir + '/provisioning/database.vwsfrienddbbackup')

engine = create_engine(dbUrl, pool_pre_ping=True)
self.session = Session(engine)
Expand Down
4 changes: 2 additions & 2 deletions vwsfriend/vwsfriend/ui/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def backup():
if current_app.configDir is None:
flash('Config directory is not configured')
else:
form.file.data.save(current_app.configDir + '/' + 'restore.vwsfriendbackup')
form.file.data.save(current_app.configDir + '/provisioning/database.vwsfrienddbbackup')
flash('backup was uploaded, now restarting to apply the backup')
return redirect(url_for('restart'))
else:
Expand All @@ -649,7 +649,7 @@ def backup():
if process.returncode != 0:
return abort(500, f"pg_dump returned {process.returncode}: {process.stderr.decode('ascii')}")
return send_file(BytesIO(process.stdout), mimetype='application/gzip', as_attachment=True,
download_name=f'{datetime.now().strftime("%Y%m%dT%H%M%S")}.vwsfriendbackup')
download_name=f'{datetime.now().strftime("%Y%m%dT%H%M%S")}.vwsfrienddbbackup')
except FileNotFoundError as e:
return abort(500, f"pg_dump was not found, you have to install it in order to be able to make database backups: {e}")

Expand Down
2 changes: 1 addition & 1 deletion vwsfriend/vwsfriend/ui/templates/database/backup.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}

{% block header %}
<h1>{% block title %}Backup & Restore{% endblock %}</h1>
<h1>{% block title %}Database Backup & Restore{% endblock %}</h1>
{% endblock %}

{% block content %}
Expand Down

0 comments on commit 16e079c

Please sign in to comment.