Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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:

  1. Database Files: Located in the data/ directory
  2. Configuration: Stored in the .env file
  3. 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:

  1. Stop the container (optional but recommended for consistency):

    docker stop kinesis-api
    
  2. Create the backup directory:

    mkdir backup/
    
  3. Back up the data directory:

    cp -r data/ backup/data/
    
  4. Back up the environment file:

    cp .env backup/.env
    
  5. Back up the public directory (if you've uploaded media):

    cp -r public/ backup/public/
    
  6. Restart the container (if you stopped it):

    docker start kinesis-api
    

Native Installation Backup

If you're running Kinesis API directly on your host:

  1. Stop the Kinesis API service:

    # If using systemd
    sudo systemctl stop kinesis-api
    
    # Or if running directly
    kill $(pgrep kinesis-api)
    
  2. 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/
    
  3. 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:

  1. Stop the running instance:

    docker stop kinesis-api
    
  2. 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/ .
    
  3. Restart the service:

    docker start kinesis-api
    

Backup Best Practices

  1. Regular Schedule: Establish a consistent backup schedule based on how frequently your data changes.

  2. 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)
  3. Verification: Periodically verify your backups by testing the restoration process in a separate environment.

  4. Automation: Automate your backup process to ensure consistency and reliability.

  5. Documentation: Keep clear documentation of your backup and restore procedures.

  6. External Storage: Store backups on external storage separate from your production environment.

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