File: //home/gisha985666/htdocs/BackupSystem/README.md
# WordPress Backup Script
A Python script that automatically backs up WordPress files and database to Google Drive.
## Features
- Zips all WordPress files and folders
- Creates MySQL database backup
- Uploads backups to Google Drive
- Automatically deletes local zip files after upload (configurable)
- Logging support
- Configurable via INI file
## Setup
### 1. Install Dependencies
```bash
pip install -r requirements.txt
```
### 2. Google Drive API Setup
1. Go to [Google Cloud Console](https://console.cloud.google.com/)
2. Create a new project or select existing one
3. Enable Google Drive API
4. Create a Service Account:
- Go to "Credentials" > "Create Credentials" > "Service Account"
- Download the JSON key file
- Save it securely and note the path
5. Share your Google Drive folder with the service account email (found in the JSON file)
### 3. Configuration
1. Copy the example config file:
```bash
cp config.ini.example config.ini
```
2. Edit `config.ini` with your settings:
- WordPress path
- Database credentials
- Google Drive credentials file path
- Google Drive folder ID (optional)
### 4. Make Script Executable
```bash
chmod +x wp_backup.py
```
## Usage
### Manual Run
```bash
python3 wp_backup.py
# or with custom config file
python3 wp_backup.py /path/to/config.ini
```
### Cron Setup
Add to crontab for automated backups:
```bash
# Edit crontab
crontab -e
# Example: Run daily at 2 AM
0 2 * * * /usr/bin/python3 /path/to/wp_backup.py /path/to/config.ini
# Example: Run every 6 hours
0 */6 * * * /usr/bin/python3 /path/to/wp_backup.py /path/to/config.ini
```
## File Structure
- `wp_backup.py` - Main backup script
- `config.ini.example` - Configuration template
- `requirements.txt` - Python dependencies
- `wp_backup.log` - Log file (created automatically)
## Backup Files
The script creates timestamped backup files:
- `wp_files_backup_YYYYMMDD_HHMMSS.zip` - WordPress files
- `wp_db_backup_YYYYMMDD_HHMMSS.zip` - Database backup
## Troubleshooting
1. **Permission Issues**: Ensure the script has read access to WordPress files and write access to backup directory
2. **Database Connection**: Verify database credentials and that mysqldump is installed
3. **Google Drive**: Check service account permissions and credentials file path
4. **Logs**: Check `wp_backup.log` for detailed error information
## Security Notes
- Keep your Google Service Account key file secure
- Use appropriate file permissions (600) for config.ini
- Consider encrypting database backups for additional security