|
| 1 | +# Quick Start Guide |
| 2 | + |
| 3 | +## 🚀 Getting Started in 5 Minutes |
| 4 | + |
| 5 | +### Prerequisites |
| 6 | + |
| 7 | +- Docker installed and running |
| 8 | +- PostgreSQL database to backup |
| 9 | +- rclone configuration for remote storage (optional) |
| 10 | + |
| 11 | +### Step 1: Prepare rclone Configuration |
| 12 | + |
| 13 | +Create a base64 encoded rclone configuration: |
| 14 | + |
| 15 | +```bash |
| 16 | +# Create rclone config file |
| 17 | +cat > rclone.conf << EOF |
| 18 | +[s3-remote] |
| 19 | +type = s3 |
| 20 | +provider = AWS |
| 21 | +access_key_id = your_access_key |
| 22 | +secret_access_key = your_secret_key |
| 23 | +region = us-east-1 |
| 24 | +EOF |
| 25 | + |
| 26 | +# Encode to base64 |
| 27 | +RCLONE_CONF_BASE64=$(cat rclone.conf | base64 -w 0) |
| 28 | +echo $RCLONE_CONF_BASE64 |
| 29 | +``` |
| 30 | + |
| 31 | +### Step 2: Run Backup Container |
| 32 | + |
| 33 | +```bash |
| 34 | +docker run -d \ |
| 35 | + --name postgres-backup \ |
| 36 | + -e POSTGRES_USER=myuser \ |
| 37 | + -e POSTGRES_PASSWORD=mypassword \ |
| 38 | + -e POSTGRES_DB=mydatabase \ |
| 39 | + -e RCLONE_CONF_BASE64="$RCLONE_CONF_BASE64" \ |
| 40 | + -e PGBACKREST_STANZA=main \ |
| 41 | + -e WAL_GROWTH_THRESHOLD="100MB" \ |
| 42 | + -v /var/lib/postgresql/data:/var/lib/postgresql/data:ro \ |
| 43 | + -v ./backup-logs:/backup/logs \ |
| 44 | + ghcr.io/whispin/postgres_nrt_backup:latest |
| 45 | +``` |
| 46 | + |
| 47 | +### Step 3: Verify Backup System |
| 48 | + |
| 49 | +```bash |
| 50 | +# Check container status |
| 51 | +docker ps | grep postgres-backup |
| 52 | + |
| 53 | +# Check logs |
| 54 | +docker logs postgres-backup |
| 55 | + |
| 56 | +# Verify backup configuration |
| 57 | +docker exec postgres-backup /backup/scripts/manual-backup.sh --check |
| 58 | +``` |
| 59 | + |
| 60 | +### Step 4: Perform Manual Backup |
| 61 | + |
| 62 | +```bash |
| 63 | +# Full backup |
| 64 | +docker exec postgres-backup /backup/scripts/manual-backup.sh --full |
| 65 | + |
| 66 | +# Check backup status |
| 67 | +docker exec postgres-backup /backup/scripts/manual-backup.sh --list |
| 68 | +``` |
| 69 | + |
| 70 | +### Step 5: Monitor WAL Growth |
| 71 | + |
| 72 | +```bash |
| 73 | +# Check WAL monitor status |
| 74 | +docker exec postgres-backup /backup/scripts/wal-control.sh status |
| 75 | + |
| 76 | +# View WAL monitor logs |
| 77 | +docker exec postgres-backup /backup/scripts/wal-control.sh logs -n 20 |
| 78 | +``` |
| 79 | + |
| 80 | +## 🔄 Recovery Example |
| 81 | + |
| 82 | +### Recover to Latest Backup |
| 83 | + |
| 84 | +```bash |
| 85 | +docker run -d \ |
| 86 | + --name postgres-recovery \ |
| 87 | + -e POSTGRES_USER=myuser \ |
| 88 | + -e POSTGRES_PASSWORD=mypassword \ |
| 89 | + -e POSTGRES_DB=mydatabase \ |
| 90 | + -e RCLONE_CONF_BASE64="$RCLONE_CONF_BASE64" \ |
| 91 | + -e RECOVERY_MODE="true" \ |
| 92 | + -v ./recovery-data:/var/lib/postgresql/data \ |
| 93 | + ghcr.io/whispin/postgres_nrt_backup:latest |
| 94 | +``` |
| 95 | + |
| 96 | +### Point-in-Time Recovery |
| 97 | + |
| 98 | +```bash |
| 99 | +docker run -d \ |
| 100 | + --name postgres-recovery \ |
| 101 | + -e POSTGRES_USER=myuser \ |
| 102 | + -e POSTGRES_PASSWORD=mypassword \ |
| 103 | + -e POSTGRES_DB=mydatabase \ |
| 104 | + -e RCLONE_CONF_BASE64="$RCLONE_CONF_BASE64" \ |
| 105 | + -e RECOVERY_MODE="true" \ |
| 106 | + -e RECOVERY_TARGET_TIME="2025-07-10 14:30:00" \ |
| 107 | + -v ./recovery-data:/var/lib/postgresql/data \ |
| 108 | + ghcr.io/whispin/postgres_nrt_backup:latest |
| 109 | +``` |
| 110 | + |
| 111 | +## 📊 Monitoring |
| 112 | + |
| 113 | +### Check Backup Status |
| 114 | + |
| 115 | +```bash |
| 116 | +# View backup logs |
| 117 | +docker exec postgres-backup tail -f /backup/logs/backup.log |
| 118 | + |
| 119 | +# Check WAL monitor |
| 120 | +docker exec postgres-backup /backup/scripts/wal-control.sh status |
| 121 | + |
| 122 | +# List all backups |
| 123 | +docker exec postgres-backup /backup/scripts/manual-backup.sh --list |
| 124 | +``` |
| 125 | + |
| 126 | +### Health Check |
| 127 | + |
| 128 | +```bash |
| 129 | +# Run health check |
| 130 | +docker exec postgres-backup /backup/scripts/healthcheck.sh |
| 131 | + |
| 132 | +# Check container health |
| 133 | +docker inspect postgres-backup | grep Health -A 10 |
| 134 | +``` |
| 135 | + |
| 136 | +## 🛠️ Troubleshooting |
| 137 | + |
| 138 | +### Common Issues |
| 139 | + |
| 140 | +1. **Container fails to start** |
| 141 | + ```bash |
| 142 | + # Check logs |
| 143 | + docker logs postgres-backup |
| 144 | + |
| 145 | + # Check environment variables |
| 146 | + docker exec postgres-backup env | grep POSTGRES |
| 147 | + ``` |
| 148 | + |
| 149 | +2. **Backup fails** |
| 150 | + ```bash |
| 151 | + # Check backup logs |
| 152 | + docker exec postgres-backup cat /backup/logs/backup.log |
| 153 | + |
| 154 | + # Test PostgreSQL connection |
| 155 | + docker exec postgres-backup pg_isready -U $POSTGRES_USER -d $POSTGRES_DB |
| 156 | + ``` |
| 157 | + |
| 158 | +3. **Remote storage issues** |
| 159 | + ```bash |
| 160 | + # Test rclone configuration |
| 161 | + docker exec postgres-backup rclone config show |
| 162 | + |
| 163 | + # Test remote connection |
| 164 | + docker exec postgres-backup /backup/scripts/recovery-control.sh test-connection |
| 165 | + ``` |
| 166 | + |
| 167 | +### Debug Mode |
| 168 | + |
| 169 | +```bash |
| 170 | +# Run with debug logging |
| 171 | +docker run -d \ |
| 172 | + --name postgres-backup \ |
| 173 | + -e DEBUG="true" \ |
| 174 | + -e POSTGRES_USER=myuser \ |
| 175 | + # ... other environment variables |
| 176 | + ghcr.io/whispin/postgres_nrt_backup:latest |
| 177 | +``` |
| 178 | + |
| 179 | +## 📚 Next Steps |
| 180 | + |
| 181 | +- Read the [Manual Backup Guide](MANUAL_BACKUP_GUIDE.md) |
| 182 | +- Learn about [WAL Monitoring](WAL_MONITOR_GUIDE.md) |
| 183 | +- Explore [Recovery Options](RECOVERY_GUIDE.md) |
| 184 | +- Understand [Smart Backup Logic](SMART_BACKUP_LOGIC.md) |
| 185 | + |
| 186 | +## 💡 Tips |
| 187 | + |
| 188 | +1. **Set appropriate WAL threshold**: Start with 100MB and adjust based on your database activity |
| 189 | +2. **Monitor backup logs**: Regularly check logs for any issues |
| 190 | +3. **Test recovery**: Periodically test your backup recovery process |
| 191 | +4. **Use health checks**: Enable Docker health checks for monitoring |
| 192 | +5. **Backup retention**: Adjust retention days based on your requirements |
| 193 | + |
| 194 | +That's it! Your PostgreSQL backup system is now running with automatic WAL monitoring and remote storage support. |
0 commit comments