This Bash script is designed to automate the backup process of a SQLite database in a project. It allows you to easily copy the database file to a specified directory for backups, with customizable naming conventions.
- Bash (Bourne Again SHell)
- SQLite database file in your project
.env
file with configuration variables (see .env_example)
-
Clone the repository to your local machine.
git clone https://github.com/DanyaSh/sqlite_backups.git
-
Navigate to the project directory.
cd /PATH/TO/THIS/PROJECT/DIRECTORY
-
Create a
.env
file based on the provided .env_example. Customize the variables according to your project configuration.CURRENT_DATE=$(date +'%Y%m%d') NAME_DB=my_database PROJECT_DB_PATH=/path/to/project/db.sqlite BACKUP_DIR=/path/to/backups
-
Make the script executable.
chmod +x back_script.sh
-
Run the script.
./back_script.sh
- NAME_DB: Name of the database.
- CURRENT_DATE: Current date in the format YYYYMMDD.
- PROJECT_DB_PATH: Path to the project's SQLite database file.
- BACKUP_DIR: Directory path for storing backups.
You can manually trigger a backup with a custom comment by providing it as an argument. This will create a backup file with a filename like:
./back_script.sh "my_custom_comment"
This will create a backup file with a filename like:
20230101_my_database_my_custom_comment.sqlite
Launch in terminal linux
crontab -e
input for example (for everyday auto backup your database at 3 am and logging this process)
0 3 * * * /path/to/your/script/back_script.sh >> /path/to/your/logs/cron.log 2>&1
launch in terminal linux
sudo visudo
input
$USER ALL=(ALL) NOPASSWD: /path/to/your/script/backup_script.sh
This project is licensed under the MIT License.