{"id":13502182,"url":"https://github.com/cuducos/alchemydumps","last_synced_at":"2025-03-29T10:32:48.984Z","repository":{"id":23331835,"uuid":"26692143","full_name":"cuducos/alchemydumps","owner":"cuducos","description":"SQLAlchemy backup/dump tool for Flask","archived":true,"fork":false,"pushed_at":"2021-09-13T16:57:55.000Z","size":174,"stargazers_count":117,"open_issues_count":5,"forks_count":29,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-03-18T12:51:41.575Z","etag":null,"topics":["database","flask","python","sqlalchemy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cuducos.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-15T20:03:05.000Z","updated_at":"2025-03-13T14:16:43.000Z","dependencies_parsed_at":"2022-08-21T16:01:15.837Z","dependency_job_id":null,"html_url":"https://github.com/cuducos/alchemydumps","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuducos%2Falchemydumps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuducos%2Falchemydumps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuducos%2Falchemydumps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuducos%2Falchemydumps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cuducos","download_url":"https://codeload.github.com/cuducos/alchemydumps/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246174207,"owners_count":20735406,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","flask","python","sqlalchemy"],"created_at":"2024-07-31T22:02:05.117Z","updated_at":"2025-03-29T10:32:48.292Z","avatar_url":"https://github.com/cuducos.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# AlchemyDumps [![Latest release](https://img.shields.io/pypi/v/Flask-AlchemyDumps.svg?style=flat)](https://pypi.python.org/pypi/Flask-AlchemyDumps)\n\n[![Development Status: Alpha](https://img.shields.io/pypi/status/Flask-AlchemyDumps.svg?style=flat)](https://pypi.python.org/pypi/Flask-AlchemyDumps)\n[![Python Version](https://img.shields.io/pypi/pyversions/Flask-AlchemyDumps.svg)](https://pypi.python.org/pypi/Flask-AlchemyDumps)\n[![GitHub Actions](https://github.com/cuducos/alchemydumps/actions/workflows/tests.yaml/badge.svg)](https://github.com/cuducos/alchemydumps/actions/workflows/tests.yaml)\n[![Coverage Status](https://coveralls.io/repos/github/cuducos/alchemydumps/badge.svg?branch=master)](https://coveralls.io/github/cuducos/alchemydumps?branch=master)\n\n\nDo you use [Flask](http://flask.pocoo.org\u003e) with [SQLAlchemy](http://www.sqlalchemy.org/)? Wow, what a coincidence!\n\nThis package lets you backup and restore all your data using [SQLAlchemy dumps() method](http://docs.sqlalchemy.org/en/latest/core/serializer.html).\n\nIt is an easy way (one single command, I mean it) to save **all** the data stored in your database.\n\nYou can save it locally or in a remote server via FTP.\n\n\u003e **WARNING** [**@baumatron**](https://github.com/baumatron)'ve [found an important bug](https://github.com/cuducos/alchemydumps/issues/13): at this time this package won't backup [non-standard mappings](http://docs.sqlalchemy.org/en/latest/orm/nonstandard_mappings.html), such as [many-to-many association tables](http://docs.sqlalchemy.org/en/latest/orm/basic_relationships.html#many-to-many). This is still an open issue and I have no expectation to fix is in the following weeks — **_pull requests_ are more tham welcomed**.\n\n## Install\n\nFirst install the package: `pip install Flask-AlchemyDumps`\n\nThen pass your Flask application and SQLALchemy database to it.\n\nFor example:\n\n* The ***second line*** imports the object from the package.\n* The ***last line*** instantiates `AlchemyDumps` for your app and database.\n\n```python\nfrom flask import Flask\nfrom flask_alchemydumps import AlchemyDumps\nfrom flask_sqlalchemy import SQLAlchemy\n\n# init Flask\napp = Flask(__name__)\n\n# init SQLAlchemy and Flask-Script\napp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'\ndb = SQLAlchemy(app)\n\n# init Alchemy Dumps\nalchemydumps = AlchemyDumps(app, db)\n```\n\n### Remote backup (via FTP)\n\nIf you want to save your backup in a remote server via FTP, just make sure to set these environment variables replacing the placeholder information with the proper credentials:\n\n```console\nexport ALCHEMYDUMPS_FTP_SERVER=ftp.server.com\nexport ALCHEMYDUMPS_FTP_USER=johndoe\nexport ALCHEMYDUMPS_FTP_PASSWORD=secret\nexport ALCHEMYDUMPS_FTP_PATH=/absolute/path/\n```\n\nIf you want, there is a `.env.sample` inside the `/tests` folder. Just copy it to your application root folder, rename it to `.env`, and insert your credentials.\n\n### Using application factory\n\nIt is possible to use this package with application factories:\n\n```python\nalchemydumps = AlchemyDumps()\n\ndef create_app(settings):\n    …\n    alchemydumps.init_app(app, db)\n    …\n```\n\n### .gitignore\n\nYou might want to add `alchemydumps/` to your `.gitignore`. It is the folder where **AlchemyDumps** save the backup files.\n\n## Examples\n\nConsidering you have these *models* — that is to say, these [SQLAlchemy mapped classes](http://docs.sqlalchemy.org/en/latest/orm/mapper_config.html):\n\n```python\nclass User(db.Model):\n    id = db.Column(db.Integer, primary_key=True)\n    email = db.Column(db.String(140), index=True, unique=True)\n    posts = db.relationship('Post', backref='author', lazy='dynamic')\n\nclass Post(db.Model):\n    id = db.Column(db.Integer, primary_key=True)\n    title = db.Column(db.String(140))\n    content = db.Column(db.UnicodeText)\n    author_id = db.Column(db.Integer, db.ForeignKey('user.id'))\n```\n\nJust in case: this is a simple example, but you can use *abstract* mapped classes as well.\n\n### You can backup all your data\n\n```console\npython manage.py alchemydumps create\n```\n\nOutput:\n\n```\n==\u003e 3 rows from User saved as /vagrant/alchemydumps/db-bkp-20141115172107-User.gz\n==\u003e 42 rows from Post saved as /vagrant/alchemydumps/db-bkp-20141115172107-Post.gz\n```\n\n### You can list the backups you have already created\n\n```console\npython manage.py alchemydumps history\n```\n\nOutput:\n\t\n```\n==\u003e ID: 20141114203949 (from Nov 15, 2014 at 17:21:07)\n    /vagrant/alchemydumps/db-bkp-20141115172107-User.gz\n    /vagrant/alchemydumps/db-bkp-20141115172107-Post.gz\n\n==\u003e ID: 20141115140629 (from Nov 15, 2014 at 14:06:29)\n    /vagrant/alchemydumps/db-bkp-20141115140629-User.gz\n    /vagrant/alchemydumps/db-bkp-20141115140629-Post.gz\n```\n\n### You can restore a backup\n\n```console\npython manage.py alchemydumps restore -d 20141115172107\n```\n\nOutput:\n\n```\n==\u003e db-bkp-20141115172107-User.gz totally restored.\n==\u003e db-bkp-20141115172107-Post.gz totally restored.\n```\n\n### You can delete an existing backup\n\n```console\npython manage.py alchemydumps remove -d 20141115172107\n```\n\nOutput:\n\n```\n==\u003e Do you want to delete the following files?\n    /vagrant/alchemydumps/db-bkp-20141115172107-User.gz\n    /vagrant/alchemydumps/db-bkp-20141115172107-Post.gz\n==\u003e Press \"Y\" to confirm, or anything else to abort: y\n    db-bkp-20141115172107-User.gz deleted.\n    db-bkp-20141115172107-Post.gz deleted.\n```\n\n### And you can use the auto-clean command\n\nThe `autoclean` command follows these rules to delete backups:\n\n* It keeps **all** the backups from the last 7 days.\n* It keeps **the most recent** backup **from each week of the last month**.\n* It keeps **the most recent** backup **from each month of the last year**.\n* It keeps **the most recent** backup **from each remaining year**.\n\n```console\npython manage.py alchemydumps autoclean\n```\n\nOutput:\n\n```\n==\u003e 8 backups will be kept:\n\n    ID: 20130703225903 (from Jul 03, 2013 at 22:59:03)\n    /vagrant/alchemydumps/db-bkp-20130703225903-User.gz\n    /vagrant/alchemydumps/db-bkp-20130703225903-Post.gz\n\n    ID: 20120405013054 (from Apr 05, 2012 at 01:30:54)\n    /vagrant/alchemydumps/db-bkp-20120405013054-User.gz\n    /vagrant/alchemydumps/db-bkp-20120405013054-Post.gz\n\n    ID: 20101123054342 (from Nov 23, 2010 at 05:43:42)\n    /vagrant/alchemydumps/db-bkp-20101123054342-User.gz\n    /vagrant/alchemydumps/db-bkp-20101123054342-Post.gz\n\n    ID: 20090708100815 (from Jul 08, 2009 at 10:08:15)\n    /vagrant/alchemydumps/db-bkp-20090708100815-User.gz\n    /vagrant/alchemydumps/db-bkp-20090708100815-Post.gz\n\n    ID: 20081208191908 (from Dec 08, 2008 at 19:19:08)\n    /vagrant/alchemydumps/db-bkp-20081208191908-User.gz\n    /vagrant/alchemydumps/db-bkp-20081208191908-Post.gz\n\n    ID: 20070114122922 (from Jan 14, 2007 at 12:29:22)\n    /vagrant/alchemydumps/db-bkp-20070114122922-User.gz\n    /vagrant/alchemydumps/db-bkp-20070114122922-Post.gz\n\n    ID: 20060911035318 (from Sep 11, 2006 at 03:53:18)\n    /vagrant/alchemydumps/db-bkp-20060911035318-User.gz\n    /vagrant/alchemydumps/db-bkp-20060911035318-Post.gz\n\n    ID: 20051108082503 (from Nov 08, 2005 at 08:25:03)\n    /vagrant/alchemydumps/db-bkp-20051108082503-User.gz\n    /vagrant/alchemydumps/db-bkp-20051108082503-Post.gz\n\n==\u003e 11 backups will be deleted:\n\n    ID: 20120123032442 (from Jan 23, 2012 at 03:24:42)\n    /vagrant/alchemydumps/db-bkp-20120123032442-User.gz\n    /vagrant/alchemydumps/db-bkp-20120123032442-Post.gz\n\n    ID: 20101029100412 (from Oct 29, 2010 at 10:04:12)\n    /vagrant/alchemydumps/db-bkp-20101029100412-User.gz\n    /vagrant/alchemydumps/db-bkp-20101029100412-Post.gz\n\n    ID: 20100526185156 (from May 26, 2010 at 18:51:56)\n    /vagrant/alchemydumps/db-bkp-20100526185156-User.gz\n    /vagrant/alchemydumps/db-bkp-20100526185156-Post.gz\n\n    ID: 20100423085529 (from Apr 23, 2010 at 08:55:29)\n    /vagrant/alchemydumps/db-bkp-20100423085529-User.gz\n    /vagrant/alchemydumps/db-bkp-20100423085529-Post.gz\n\n    ID: 20081006074458 (from Oct 06, 2008 at 07:44:58)\n    /vagrant/alchemydumps/db-bkp-20081006074458-User.gz\n    /vagrant/alchemydumps/db-bkp-20081006074458-Post.gz\n\n    ID: 20080429210254 (from Apr 29, 2008 at 21:02:54)\n    /vagrant/alchemydumps/db-bkp-20080429210254-User.gz\n    /vagrant/alchemydumps/db-bkp-20080429210254-Post.gz\n\n    ID: 20080424043716 (from Apr 24, 2008 at 04:37:16)\n    /vagrant/alchemydumps/db-bkp-20080424043716-User.gz\n    /vagrant/alchemydumps/db-bkp-20080424043716-Post.gz\n\n    ID: 20080405110244 (from Apr 05, 2008 at 11:02:44)\n    /vagrant/alchemydumps/db-bkp-20080405110244-User.gz\n    /vagrant/alchemydumps/db-bkp-20080405110244-Post.gz\n\n    ID: 20060629054914 (from Jun 29, 2006 at 05:49:14)\n    /vagrant/alchemydumps/db-bkp-20060629054914-User.gz\n    /vagrant/alchemydumps/db-bkp-20060629054914-Post.gz\n\n    ID: 20060329020048 (from Mar 29, 2006 at 02:00:48)\n    /vagrant/alchemydumps/db-bkp-20060329020048-User.gz\n    /vagrant/alchemydumps/db-bkp-20060329020048-Post.gz\n\n    ID: 20050324012859 (from Mar 24, 2005 at 01:28:59)\n    /vagrant/alchemydumps/db-bkp-20050324012859-User.gz\n    /vagrant/alchemydumps/db-bkp-20050324012859-Post.gz\n\n==\u003e Press \"Y\" to confirm, or anything else to abort. y\n    db-bkp-20120123032442-User.gz deleted.\n    db-bkp-20120123032442-Post.gz deleted.\n    db-bkp-20101029100412-User.gz deleted.\n    db-bkp-20101029100412-Post.gz deleted.\n    db-bkp-20100526185156-User.gz deleted.\n    db-bkp-20100526185156-Post.gz deleted.\n    db-bkp-20100423085529-User.gz deleted.\n    db-bkp-20100423085529-Post.gz deleted.\n    db-bkp-20081006074458-User.gz deleted.\n    db-bkp-20081006074458-Post.gz deleted.\n    db-bkp-20080429210254-User.gz deleted.\n    db-bkp-20080429210254-Post.gz deleted.\n    db-bkp-20080424043716-User.gz deleted.\n    db-bkp-20080424043716-Post.gz deleted.\n    db-bkp-20080405110244-User.gz deleted.\n    db-bkp-20080405110244-Post.gz deleted.\n    db-bkp-20060629054914-User.gz deleted.\n    db-bkp-20060629054914-Post.gz deleted.\n    db-bkp-20060329020048-User.gz deleted.\n    db-bkp-20060329020048-Post.gz deleted.\n    db-bkp-20050324012859-User.gz deleted.\n    db-bkp-20050324012859-Post.gz deleted.\n```\n\n## Requirements \u0026 Dependencies\n\n**AlchemyDumps** is tested and should work with Python 3.6+.\n\n## Tests\n\nIf you wanna run the tests for the current Python version:\n\n```console\npoetry install\npoetry run nosetests\n```\n\nWe also use some style and quality checkers:\n\n```console\npoetry run black . --check\npoetry run flake8 flask_alchemydumps/ tests/\n```\n\nIf you wanna cover all supported Python version, you need them installed and available via [`pyenv`](https://github.com/pyenv/pyenv). Then just `poetry run tox`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuducos%2Falchemydumps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcuducos%2Falchemydumps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuducos%2Falchemydumps/lists"}