Crates.io | r-backups |
lib.rs | r-backups |
version | 0.1.2 |
source | src |
created_at | 2024-12-06 00:26:54.962928 |
updated_at | 2024-12-13 00:02:29.633643 |
description | Tool for managing databases and backups |
homepage | https://github.com/HormigaDev/r-backups |
repository | https://github.com/HormigaDev/r-backups |
max_upload_size | |
id | 1473769 |
size | 106,577 |
This project is designed to manage centralized databases. The CLI performs operations such as backups, restores, creating databases from a .sql
file, and more.
This project is designed for environments where postgresql
is used.
Instructions to install the CLI on different operating systems.
cargo install r-backups
git clone https://github.com/HormigaDev/r-backups.git
cd r-backups
cargo build --release
Basic explanation of how to use the CLI.
r-backups [options] [arguments]
<> means required and [] means optional
For the CLI to work correctly, you must have the following environment variables configured in a .env
file in the directory where you will use the CLI or in the system's environment variables.
DATABASE_HOST=<host>
DATABASE_USER=<user>
DATABASE_PASSWORD=<password>
DATABASE_NAME=<database name>
DATABASE_PORT=<port>
BACKUPS_DIR=path/to/backups_directory/
MIGRATIONS_DIR=path/to/migrations_directory/
CHANGELOG_FILE_PATH=path/to/chagelog
r-backups init
Note:
The changelog file conventionally has no extension, and its content must initially be an empty array or an array of objects in the following format:
[
{
"id": "migration_id",
"group": "database_prefix e.g., (company_)"
}
]
backup
This command creates a backup of a specific database.
r-backups backup --database <database_name>
For this command to work correctly, the backups
configuration must be set.
See Configuration.
restore
This command restores a backup from a specified file.
r-backups restore --database <database_name> --file path/to/backup_file.backup.sql
migration
This command is used to apply or revert a specific migration for a group of databases.
You can also use this command to generate a new migration.
Generating a new migration:
r-backups migration --generate --group <group_name> --name <migration_name>
When generating a migration, the CLI uses a unique identifier for each migration, consisting of a 5-digit numeric prefix.
For example, the CLI could generate a migration named 00001_create_table_users.sql
.
The migration body contains the following:
-- up
your SQL code here;
-- down
your rollback SQL code here;
It is IMPORTANT not to delete the -- up
or -- down
comments so the CLI can identify them correctly.
Updating a group of databases:
r-backups migration --up --id <migration_id> --group <group_name>
Reverting a specific migration:
r-backups migration --down --id <migration_id> --group <group_name>
Note:
For this command to work correctly, the changelog
and migrations
configurations must be set.
See Configuration.
update
This command applies all pending migrations to a group of databases or a specific database.
It can also rollback the last migration for a group of databases or a specific database.
Updating a group of databases:
r-backups update --apply --group <group_name>
Updating a specific database:
r-backups update --apply --database <database_name>
Rolling back the last migration for a group of databases:
r-backups update --rollback --group <group_name>
Rolling back the last migration for a specific database:
r-backups update --rollback --database <database_name>
createdb
This command creates a database with a specified name.
r-backups createdb --name <database_name> --sql [path/to/file.sql]
drop
This command drops a database and requires confirmation before deletion.
r-backups drop --database <database_name>
list
This command lists all existing databases.
r-backups list
count
This command returns the number of databases present, including templates.
r-backups count
rename
This command renames a database to a specified new name.
r-backups rename --database <old_name> --to <new_name>
Option | Description |
---|---|
-h , --help |
Displays the command's help information. |
-v , --version |
Displays the current CLI version. |
init |
Initializes the CLI with default settings. |
r-backups createdb --name example_1
Contributions are welcome! If you'd like to contribute, follow these steps:
git checkout -b my-feature
).Make sure to follow Rust style guides and include unit tests whenever possible.
This project is licensed under the MIT License. See the LICENSE file for more details.