Simple backup (and restore) for small to medium projects.
Provides a toolkit for easy backups and restores of Ecto repositories in development environments via Mix tasks, and in production environments via release scripts, with support for scheduling automatic backups with cron syntax.
- Easy to use Mix tasks for backup and restore in dev and test environments.
- Release tasks for performing backup and restore in production releases.
- Scheduled automatic backups with cron-like scheduling on a per-repo basis.
- Support for backing up (and restoring) multiple Ecto repositories in a single operation.
- Configuration options for customizing backup and restore behavior globally or per-repo.
- Progress reporting and logging during backup and restore operations for CLI feedback.
- Pluggable adapters to support any database supported by Ecto.
This library provides simple backup and restore functionality for Ecto repositories, it may not be a complete backup solution for all use cases. It is recommended to evaluate your specific backup and restore requirements and ensure that this library meets those needs before relying on it for critical data protection. Always test your backups and restores to ensure they work as expected. Always keep your backups secure and follow best practices for data protection.
- PostgreSQL (via
pg_dumpandpg_restore) - MySQL / MariaDB (via
mysqldumpandmysql) *COMING SOON - SQLite (via VACUUM INTO) *COMING SOON
The package can be installed by adding ecto_backup to your list of dependencies in mix.exs:
def deps do
[
{:ecto_backup, "~> 0.1.0"}
]
endThen, run mix deps.get to fetch the new dependency.
Configure the default list of repositories to backup and where to store the backups. These are
required for normal operation, such as being able to just call mix ecto_backup.backup. They can
be overridden when using mix tasks, release tasks, scheduled backups, or direct API calls. They
can also be overridden on a per-repo basis.
config :ecto_backup,
repos: [MyApp.Repo],
backup_path: "/path/to/backups"See EctoBackup for more information on configuration and usage, and the Backup Mix Task, Restore Mix Task, Release Module, and Scheduler for more information on those components.
To enable scheduled backups, add the EctoBackup.Scheduler to your supervision tree:
# application.ex
children = [
# Other children...
EctoBackup.Scheduler
]
# config.exs
config :ecto_backup,
repos: [MyApp.Repo],
backup_path: "/path/to/backups",
backup_schedule: "0 2 * * *", # Every day at 2 AM (cron format)
backup_stagger_sec: 600, # Random delay up to 600 seconds
backup_node: :my_app@my_host # Node to perform the backup onSee EctoBackup.Scheduler for more information on scheduling options, including backing up multiple repos on different schedules.
Create aliases for the Mix tasks in your mix.exs file to save a few keystrokes:
defp aliases do
[
"ecto.backup": ["ecto_backup.backup"],
"ecto.restore": ["ecto_backup.restore"]
]
endIf, in the future, Ecto adds built-in backup and restore tasks, you can easily change or remove your aliases to use those instead.
Create release shell scripts to run the backup and restore tasks in your release environment. See EctoBackup.Release for more information.
$ mix ecto_backup.gen.releaseThis will create two scripts, backup and restore, in the rel/commands directory. You can
customize these scripts as needed, then copy them to your release's bin directory during
deployment. By default they simply use the eval command to run the appropriate functions in the
EctoBackup.Release module. They take all of the same options as the Mix tasks, and have the same
behavior and functionality.
In environments with Mix (development, test):
$ mix ecto_backup.backup
$ mix ecto_backup.restore /path/to/backup/file.dbIn release environments (without Mix, such as production and staging):
$ bin/backup
$ bin/restore /path/to/backup/file.dbThe documentation for EctoBackup can be found at https://hexdocs.pm/ecto_backup.
Contributions are welcome! Please open issues and submit pull requests on the GitHub repository.
EctoBackup is released under the MIT License. See the LICENSE.md file for details.