Backups
Regular backups are a critical component of maintaining a reliable Kinesis API installation. This guide covers how to properly back up your Kinesis API data and configuration, ensuring you can recover from unexpected failures or data corruption.
Understanding Kinesis API's Data Storage
Before discussing backup strategies, it's important to understand where Kinesis API stores its data:
- Database Files: Located in the
data/
directory - Configuration: Stored in the
.env
file - Media Files: Stored in the
public/
directory
A complete backup must include all three components to ensure full recovery.
Manual Backup Methods
Docker Installation Backup
If you're running Kinesis API via Docker (the recommended method), follow these steps:
-
Stop the container (optional but recommended for consistency):
docker stop kinesis-api
-
Create the backup directory:
mkdir backup/
-
Back up the data directory:
cp -r data/ backup/data/
-
Back up the environment file:
cp .env backup/.env
-
Back up the public directory (if you've uploaded media):
cp -r public/ backup/public/
-
Restart the container (if you stopped it):
docker start kinesis-api
Native Installation Backup
If you're running Kinesis API directly on your host:
-
Stop the Kinesis API service:
# If using systemd sudo systemctl stop kinesis-api # Or if running directly kill $(pgrep kinesis-api)
-
Back up the required directories and files:
cp -r /path/to/kinesis-api/data/ /path/to/backup/data/ cp /path/to/kinesis-api/.env /path/to/backup/.env cp -r /path/to/kinesis-api/public/ /path/to/backup/public/
-
Restart the service:
# If using systemd sudo systemctl start kinesis-api # Or if running directly cd /path/to/kinesis-api && ./target/release/kinesis-api &
Automated Backup Scripts
Simple Daily Backup Script
Create a file called backup-kinesis-api.sh
:
#!/bin/bash
# Kinesis API Backup Script
# Configuration
KINESIS_DIR="/path/to/kinesis-api"
BACKUP_DIR="/path/to/backups"
BACKUP_NAME="kinesis-api-backup-$(date +%Y%m%d-%H%M%S)"
# Create backup directory
mkdir -p "$BACKUP_DIR/$BACKUP_NAME"
# Optional: Stop the container for consistent backups
docker stop kinesis-api
# Copy the data
cp -r "$KINESIS_DIR/data" "$BACKUP_DIR/$BACKUP_NAME/"
cp "$KINESIS_DIR/.env" "$BACKUP_DIR/$BACKUP_NAME/"
cp -r "$KINESIS_DIR/public" "$BACKUP_DIR/$BACKUP_NAME/"
# Restart the container
docker start kinesis-api
# Compress the backup
cd "$BACKUP_DIR"
tar -czf "$BACKUP_NAME.tar.gz" "$BACKUP_NAME"
rm -rf "$BACKUP_NAME"
# Optional: Rotate backups (keep last 7 days)
find "$BACKUP_DIR" -name "kinesis-api-backup-*.tar.gz" -type f -mtime +7 -delete
echo "Backup completed: $BACKUP_DIR/$BACKUP_NAME.tar.gz"
Make the script executable and schedule it with cron:
chmod +x backup-kinesis-api.sh
crontab -e
Add a line to run it daily at 2 AM:
0 2 * * * /path/to/backup-kinesis-api.sh
Restoring from Backup
To restore Kinesis API from a backup:
-
Stop the running instance:
docker stop kinesis-api
-
Replace the data with the backup:
# If your backup is compressed tar -xzf kinesis-backup.tar.gz # Replace the current data rm -rf data/ .env public/ cp -r backup/data/ . cp backup/.env . cp -r backup/public/ .
-
Restart the service:
docker start kinesis-api
Backup Best Practices
-
Regular Schedule: Establish a consistent backup schedule based on how frequently your data changes.
-
Multiple Backup Copies: Follow the 3-2-1 backup rule:
- Keep 3 copies of your data
- Use 2 different storage types
- Store 1 copy off-site (different physical location)
-
Verification: Periodically verify your backups by testing the restoration process in a separate environment.
-
Automation: Automate your backup process to ensure consistency and reliability.
-
Documentation: Keep clear documentation of your backup and restore procedures.
-
External Storage: Store backups on external storage separate from your production environment.
-
Encryption: Consider encrypting sensitive backup data, especially when storing off-site.
Remote Backup Solutions
For enhanced security and reliability, consider these options for storing backups remotely:
Cloud Storage
Configure your backup script to upload to cloud storage:
# Example for AWS S3
aws s3 cp "$BACKUP_DIR/$BACKUP_NAME.tar.gz" "s3://your-bucket/kinesis-backups/"
# Example for Google Cloud Storage
gsutil cp "$BACKUP_DIR/$BACKUP_NAME.tar.gz" "gs://your-bucket/kinesis-backups/"
SFTP/SCP Transfer
Transfer backups to a remote server:
scp "$BACKUP_DIR/$BACKUP_NAME.tar.gz" user@remote-server:/path/to/backups/