Name | DSLR JSON |
Version |
0.6.0
JSON |
| download |
home_page | None |
Summary | Take lightning fast snapshots of your local Postgres databases. |
upload_time | 2025-07-09 01:27:01 |
maintainer | None |
docs_url | None |
author | Mitchel Cabuloy |
requires_python | <4.0,>=3.9 |
license | MIT |
keywords |
database
snapshot
backup
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<br />
<br />
<p align="center">
<a href="https://github.com/mixxorz/DSLR">
<img width="281" height="84" src="https://user-images.githubusercontent.com/3102758/181914025-44bff27e-aac1-4d1b-a037-9fa98f9fed65.png" alt="The DSLR logo">
</a>
</p>
<br />
<p align="center">
<a href=""><img src="" alt=""></a>
<a href="https://badge.fury.io/py/dslr"><img src="https://badge.fury.io/py/dslr.svg" alt="PyPI version"></a>
<a href="https://pypi.python.org/pypi/dslr/"><img src="https://img.shields.io/pypi/pyversions/dslr.svg" alt="PyPI Supported Python Versions"></a>
<a href="https://github.com/mixxorz/dslr"><img src="https://github.com/mixxorz/dslr/actions/workflows/tests.yml/badge.svg" alt="GitHub Actions (Code quality and tests)"></a>
</p>
<p align="center">
<img src="https://user-images.githubusercontent.com/3102758/190845105-dd2ec4e6-286b-431d-a33d-490805852b68.png" alt="A terminal showing DSLR's command line interface.">
</p>
---
Database Snapshot, List, and Restore
Take lightning fast snapshots of your local Postgres databases.
## What is this?
DSLR is a tool that allows you to quickly take and restore database snapshots
when you're writing database migrations, switching branches, or messing with
SQL.
It's meant to be a spiritual successor to
[Stellar](https://github.com/fastmonkeys/stellar).
**Important:** DSLR is intended for development use only. It is not advisable to
use DSLR on production databases.
## Performance
DSLR is much faster than the standard `pg_dump`/`pg_restore` approach to snapshots.
<p align="center">
<img src="https://user-images.githubusercontent.com/3102758/182014327-1b13da6e-63ad-4bbe-817e-7d6c66befc98.png" alt="A chart comparing the execution time between DSLR and pg_dump/pg_restore. For snapshot and restore, DSLR took 4.125 seconds and 4.431 seconds respectively. pg_dump/pg_restore took 36.602 seconds and 13.257 seconds respectively.">
</p>
DSLR is 8x faster at taking snapshots and 3x faster at restoring snapshots compared to the `pg_dump`/`pg_restore` approach.
<details>
<summary>Testing methodology</summary>
I spun up Postgres 12.3 using Docker, created a test database, and filled it with 1GB of random data using this script:
```SQL
CREATE TABLE large_test (num1 bigint, num2 double precision, num3 double precision);
INSERT INTO large*test (num1, num2, num3)
SELECT round(random() * 10), random(), random() \_ 142
FROM generate_series(1, 20000000) s(i);
```
I used the following commands to measure the execution time:
```
time dslr snapshot my-snapshot
time dslr restore my-snapshot
time pg_dump -Fc -f export.dump
time pg_restore --no-acl --no-owner export.dump
```
I ran each command three times and plotted the mean in the chart.
Here's the raw data:
| Command | Run | Execution time (seconds) |
| ------------- | --- | ------------------------ |
| dslr snapshot | 1 | 4.797 |
| | 2 | 4.650 |
| | 3 | 2.927 |
| dslr restore | 1 | 5.840 |
| | 2 | 4.122 |
| | 3 | 3.331 |
| pg_dump | 1 | 37.345 |
| | 2 | 36.227 |
| | 3 | 36.233 |
| pg_restore | 1 | 13.304 |
| | 2 | 13.148 |
| | 3 | 13.320 |
</details>
## Install
```
pip install DSLR psycopg2 # or psycopg2-binary, or psycopg
```
**Install using pipx**
```
pipx install DSLR[psycopg2] # or psycopg2-binary, or psycopg
````
Note: The DSLR `export` and `import` snapshot commands require `pg_dump` and
`pg_restore` to be present in your `PATH`, so you will need the Postgres CLI
utilities if you want to use those commands.
<details>
<summary><strong>Shell completion</strong></summary>
**Bash**
Add this to `~/.bashrc`:
```
eval "$(_DSLR_COMPLETE=bash_source dslr)"
```
**Zsh**
Add this to `~/.zshrc`:
```
eval "$(_DSLR_COMPLETE=zsh_source dslr)"
```
**Fish**
Add this to `~/.config/fish/completions/dslr.fish`:
```
eval (env _DSLR_COMPLETE=fish_source dslr)
```
This is the same file used for the activation script method below. For Fish it’s probably always easier to use that method.
Using eval means that the command is invoked and evaluated every time a shell is started, which can delay shell responsiveness. To speed it up, write the generated script to a file, then source that.
**Bash**
Save the script somewhere.
```
_DSLR_COMPLETE=bash_source dslr > ~/.dslr-complete.bash
```
Source the file in ~/.bashrc.
```
. ~/.dslr-complete.bash
```
**Zsh**
Save the script somewhere.
```
_DSLR_COMPLETE=zsh_source dslr > ~/.dslr-complete.zsh
```
Source the file in ~/.zshrc.
```
. ~/.dslr-complete.zsh
```
**Fish**
Save the script to ~/.config/fish/completions/foo-bar.fish:
```
_DSLR_COMPLETE=fish_source dslr > ~/.config/fish/completions/dslr.fish
```
</details>
## Configuration
You can tell DSLR which database to take snapshots of in a few ways:
**DATABASE_URL**
If the `DATABASE_URL` environment variable is set, DSLR will use this to connect
to your target database.
```bash
export DATABASE_URL=postgres://username:password@host:port/database_name
````
**dslr.toml**
If a `dslr.toml` file exists in the current directory, DSLR will read its
settings from there. DSLR will prefer this over the environment variable.
```toml
url = 'postgres://username:password@host:port/database_name'
```
**`--url` option**
Finally, you can explicitly pass the connection string via the `--url` option.
This will override any of the above settings.
## Usage
```
$ dslr snapshot my-first-snapshot
Created new snapshot my-first-snapshot
$ dslr restore my-first-snapshot
Restored database from snapshot my-first-snapshot
$ dslr list
Name Created Size
─────────────────────────────────────────────
my-first-snapshot 2 minutes ago 3253 kB
$ dslr rename my-first-snapshot fresh-db
Renamed snapshot my-first-snapshot to fresh-db
$ dslr delete some-old-snapshot
Deleted some-old-snapshot
$ dslr export my-feature-test
Exported snapshot my-feature-test to my-feature-test_20220730-075650.dump
$ dslr import snapshot-from-a-friend_20220730-080632.dump friend-snapshot
Imported snapshot friend-snapshot from snapshot-from-a-friend_20220730-080632.dump
```
To force overwriting an existing snapshot in non-interactive shell use the flag `-y`:
```
$ dslr snapshot my-first-snapshot -y
Updated snapshot my-first-snapshot
```
## How does it work?
DSLR takes snapshots by cloning databases using Postgres' [Template
Databases](https://www.postgresql.org/docs/current/manage-ag-templatedbs.html)
functionality. This is the main source of DSLR's speed.
This means that taking a snapshot is just creating a new database using the main
database as the template. Restoring a snapshot is just deleting the main
database and creating a new database using the snapshot database as the
template. So on and so forth.
## Contributors
[](https://github.com/mixxorz/DSLR/graphs/contributors)
## License
MIT
Raw data
{
"_id": null,
"home_page": null,
"name": "DSLR",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "database, snapshot, backup",
"author": "Mitchel Cabuloy",
"author_email": "mixxorz@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/12/1b/07c6710d1829d31e211124093db8f6f9964b224a3097e717af7e3b7e4cc2/dslr-0.6.0.tar.gz",
"platform": null,
"description": "<br />\n<br />\n<p align=\"center\">\n <a href=\"https://github.com/mixxorz/DSLR\">\n <img width=\"281\" height=\"84\" src=\"https://user-images.githubusercontent.com/3102758/181914025-44bff27e-aac1-4d1b-a037-9fa98f9fed65.png\" alt=\"The DSLR logo\">\n </a>\n</p>\n<br />\n\n<p align=\"center\">\n <a href=\"\"><img src=\"\" alt=\"\"></a>\n <a href=\"https://badge.fury.io/py/dslr\"><img src=\"https://badge.fury.io/py/dslr.svg\" alt=\"PyPI version\"></a>\n <a href=\"https://pypi.python.org/pypi/dslr/\"><img src=\"https://img.shields.io/pypi/pyversions/dslr.svg\" alt=\"PyPI Supported Python Versions\"></a>\n <a href=\"https://github.com/mixxorz/dslr\"><img src=\"https://github.com/mixxorz/dslr/actions/workflows/tests.yml/badge.svg\" alt=\"GitHub Actions (Code quality and tests)\"></a>\n\n</p>\n\n<p align=\"center\">\n <img src=\"https://user-images.githubusercontent.com/3102758/190845105-dd2ec4e6-286b-431d-a33d-490805852b68.png\" alt=\"A terminal showing DSLR's command line interface.\">\n</p>\n\n---\n\nDatabase Snapshot, List, and Restore\n\nTake lightning fast snapshots of your local Postgres databases.\n\n## What is this?\n\nDSLR is a tool that allows you to quickly take and restore database snapshots\nwhen you're writing database migrations, switching branches, or messing with\nSQL.\n\nIt's meant to be a spiritual successor to\n[Stellar](https://github.com/fastmonkeys/stellar).\n\n**Important:** DSLR is intended for development use only. It is not advisable to\nuse DSLR on production databases.\n\n## Performance\n\nDSLR is much faster than the standard `pg_dump`/`pg_restore` approach to snapshots.\n\n<p align=\"center\">\n <img src=\"https://user-images.githubusercontent.com/3102758/182014327-1b13da6e-63ad-4bbe-817e-7d6c66befc98.png\" alt=\"A chart comparing the execution time between DSLR and pg_dump/pg_restore. For snapshot and restore, DSLR took 4.125 seconds and 4.431 seconds respectively. pg_dump/pg_restore took 36.602 seconds and 13.257 seconds respectively.\">\n</p>\n\nDSLR is 8x faster at taking snapshots and 3x faster at restoring snapshots compared to the `pg_dump`/`pg_restore` approach.\n\n<details>\n <summary>Testing methodology</summary>\n \n I spun up Postgres 12.3 using Docker, created a test database, and filled it with 1GB of random data using this script:\n \n ```SQL\n CREATE TABLE large_test (num1 bigint, num2 double precision, num3 double precision);\n\nINSERT INTO large*test (num1, num2, num3)\nSELECT round(random() * 10), random(), random() \\_ 142\nFROM generate_series(1, 20000000) s(i);\n\n```\n\nI used the following commands to measure the execution time:\n\n```\n\ntime dslr snapshot my-snapshot\ntime dslr restore my-snapshot\ntime pg_dump -Fc -f export.dump\ntime pg_restore --no-acl --no-owner export.dump\n\n```\n\nI ran each command three times and plotted the mean in the chart.\n\nHere's the raw data:\n\n| Command | Run | Execution time (seconds) |\n| ------------- | --- | ------------------------ |\n| dslr snapshot | 1 | 4.797 |\n| | 2 | 4.650 |\n| | 3 | 2.927 |\n| dslr restore | 1 | 5.840 |\n| | 2 | 4.122 |\n| | 3 | 3.331 |\n| pg_dump | 1 | 37.345 |\n| | 2 | 36.227 |\n| | 3 | 36.233 |\n| pg_restore | 1 | 13.304 |\n| | 2 | 13.148 |\n| | 3 | 13.320 |\n</details>\n\n## Install\n\n```\n\npip install DSLR psycopg2 # or psycopg2-binary, or psycopg\n\n```\n\n**Install using pipx**\n\n```\n\npipx install DSLR[psycopg2] # or psycopg2-binary, or psycopg\n\n````\n\nNote: The DSLR `export` and `import` snapshot commands require `pg_dump` and\n`pg_restore` to be present in your `PATH`, so you will need the Postgres CLI\nutilities if you want to use those commands.\n\n<details>\n <summary><strong>Shell completion</strong></summary>\n\n**Bash**\n\nAdd this to `~/.bashrc`:\n\n```\neval \"$(_DSLR_COMPLETE=bash_source dslr)\"\n```\n\n**Zsh**\n\nAdd this to `~/.zshrc`:\n\n```\neval \"$(_DSLR_COMPLETE=zsh_source dslr)\"\n```\n\n**Fish**\n\nAdd this to `~/.config/fish/completions/dslr.fish`:\n\n```\neval (env _DSLR_COMPLETE=fish_source dslr)\n```\n\nThis is the same file used for the activation script method below. For Fish it\u2019s probably always easier to use that method.\n\nUsing eval means that the command is invoked and evaluated every time a shell is started, which can delay shell responsiveness. To speed it up, write the generated script to a file, then source that.\n\n**Bash**\n\nSave the script somewhere.\n\n```\n_DSLR_COMPLETE=bash_source dslr > ~/.dslr-complete.bash\n```\n\nSource the file in ~/.bashrc.\n\n```\n. ~/.dslr-complete.bash\n```\n\n**Zsh**\n\nSave the script somewhere.\n\n```\n_DSLR_COMPLETE=zsh_source dslr > ~/.dslr-complete.zsh\n```\n\nSource the file in ~/.zshrc.\n\n```\n. ~/.dslr-complete.zsh\n```\n\n**Fish**\n\nSave the script to ~/.config/fish/completions/foo-bar.fish:\n\n```\n_DSLR_COMPLETE=fish_source dslr > ~/.config/fish/completions/dslr.fish\n```\n\n</details>\n\n\n\n## Configuration\n\nYou can tell DSLR which database to take snapshots of in a few ways:\n\n**DATABASE_URL**\n\nIf the `DATABASE_URL` environment variable is set, DSLR will use this to connect\nto your target database.\n\n```bash\nexport DATABASE_URL=postgres://username:password@host:port/database_name\n````\n\n**dslr.toml**\n\nIf a `dslr.toml` file exists in the current directory, DSLR will read its\nsettings from there. DSLR will prefer this over the environment variable.\n\n```toml\nurl = 'postgres://username:password@host:port/database_name'\n```\n\n**`--url` option**\n\nFinally, you can explicitly pass the connection string via the `--url` option.\nThis will override any of the above settings.\n\n## Usage\n\n```\n$ dslr snapshot my-first-snapshot\nCreated new snapshot my-first-snapshot\n\n$ dslr restore my-first-snapshot\nRestored database from snapshot my-first-snapshot\n\n$ dslr list\n\n Name Created Size\n \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n my-first-snapshot 2 minutes ago 3253 kB\n\n$ dslr rename my-first-snapshot fresh-db\nRenamed snapshot my-first-snapshot to fresh-db\n\n$ dslr delete some-old-snapshot\nDeleted some-old-snapshot\n\n$ dslr export my-feature-test\nExported snapshot my-feature-test to my-feature-test_20220730-075650.dump\n\n$ dslr import snapshot-from-a-friend_20220730-080632.dump friend-snapshot\nImported snapshot friend-snapshot from snapshot-from-a-friend_20220730-080632.dump\n```\n\nTo force overwriting an existing snapshot in non-interactive shell use the flag `-y`:\n\n```\n$ dslr snapshot my-first-snapshot -y\nUpdated snapshot my-first-snapshot\n```\n\n## How does it work?\n\nDSLR takes snapshots by cloning databases using Postgres' [Template\nDatabases](https://www.postgresql.org/docs/current/manage-ag-templatedbs.html)\nfunctionality. This is the main source of DSLR's speed.\n\nThis means that taking a snapshot is just creating a new database using the main\ndatabase as the template. Restoring a snapshot is just deleting the main\ndatabase and creating a new database using the snapshot database as the\ntemplate. So on and so forth.\n\n## Contributors\n\n[](https://github.com/mixxorz/DSLR/graphs/contributors)\n\n## License\n\nMIT\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Take lightning fast snapshots of your local Postgres databases.",
"version": "0.6.0",
"project_urls": {
"Homepage": "https://github.com/mixxorz/DSLR",
"Repository": "https://github.com/mixxorz/DSLR"
},
"split_keywords": [
"database",
" snapshot",
" backup"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "6ef38091526d8106c21bac9e0b23753f4351ede871bb82f97229e55228dbf89f",
"md5": "1870dc7372d78ebfbdb81890c896457e",
"sha256": "3accbc79f53c3bfd0a0792147fc907b28c88b3444c8617ca6fb33db98b7120c3"
},
"downloads": -1,
"filename": "dslr-0.6.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1870dc7372d78ebfbdb81890c896457e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 11194,
"upload_time": "2025-07-09T01:27:00",
"upload_time_iso_8601": "2025-07-09T01:27:00.433232Z",
"url": "https://files.pythonhosted.org/packages/6e/f3/8091526d8106c21bac9e0b23753f4351ede871bb82f97229e55228dbf89f/dslr-0.6.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "121b07c6710d1829d31e211124093db8f6f9964b224a3097e717af7e3b7e4cc2",
"md5": "70096c7f794e1016e884b15aeb9923a8",
"sha256": "e8c8ce2f51f979761def676c71c442711e1dd7c5e8638f32d1118860ed6550ad"
},
"downloads": -1,
"filename": "dslr-0.6.0.tar.gz",
"has_sig": false,
"md5_digest": "70096c7f794e1016e884b15aeb9923a8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 11517,
"upload_time": "2025-07-09T01:27:01",
"upload_time_iso_8601": "2025-07-09T01:27:01.522044Z",
"url": "https://files.pythonhosted.org/packages/12/1b/07c6710d1829d31e211124093db8f6f9964b224a3097e717af7e3b7e4cc2/dslr-0.6.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-09 01:27:01",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mixxorz",
"github_project": "DSLR",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "dslr"
}