This script automates the backup process for a project's code files, implements a rotational backup strategy, and integrates with Google Drive to push the backups to a specified folder. Additionally, it deletes older backups according to the rotational strategy and sends a webhook notification on successful backup.
- Python 3.x
- Google API Python Client
- Google Auth
- Requests
- Clone the repository:
git clone https://github.com/djharshit/backup-script
cd backup-script- Install the required Python packages:
pip3 install -r requirements.txt- Set up your environment variables in a
.envfile:
PROJECT_PATH=/path/to/your/project
GDRIVE_FOLDER_ID=your_google_drive_folder_id
RETENTION=retention_number
USE_WEBHOOK=True
WEBHOOK_URL=your_webhook_url- Google Drive Integration:
- Ensure you have a credentials.json file for Google Drive API authentication. Place the file in the root directory of the project.
- Environment Variables:
- PROJECT_PATH: Path to the project folder you want to back up.
- GDRIVE_FOLDER_ID: Google Drive folder ID where backups will be uploaded.
- RETENTION: Number of days to retain backups.
- WEBHOOK_URL: URL to send a webhook notification on successful backup.
- USE_WEBHOOK: Set to
Trueto enable webhook notifications.
Run the script:
python3 one.pyThe script logs all activities to logs.log file, including backup creation, upload status, and cleanup of old backups.
The script deletes old backups from the backups directory based on the retention period specified in the environment variables.