Skip to content

DanyaSh/sqlite_backups

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🪶SQLite backup script

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.

Prerequisites

  • Bash (Bourne Again SHell)
  • SQLite database file in your project
  • .env file with configuration variables (see .env_example)

Getting Started

  1. Clone the repository to your local machine.

    git clone https://github.com/DanyaSh/sqlite_backups.git
  2. Navigate to the project directory.

    cd /PATH/TO/THIS/PROJECT/DIRECTORY
  3. 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
    
  4. Make the script executable.

    chmod +x back_script.sh
  5. Run the script.

    ./back_script.sh

Configuration

  • 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.

Usage

Manual Backup

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

Auto Backup with CRON

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

Errors

if you need sudo for script in cron:

launch in terminal linux

sudo visudo

input

$USER ALL=(ALL) NOPASSWD: /path/to/your/script/backup_script.sh

Licence

This project is licensed under the MIT License.

About

🪶SQLite backup script

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages