*Cube-Host– full cloud services!!

How to set up automatic backups using built-in tools

How to set up automatic backups using built-in tools

Backups should be automatic, predictable, and testable. The best backup is the one you can restore quickly. In this guide you’ll set up automatic backups using built-in tools on Linux (cron + tar/rsync) and Windows (Windows Server Backup + Task Scheduler).

These methods are ideal for production on Linux VPS and Windows VPS hosted on reliable VPS hosting, where you want a clean baseline without third-party backup software.

Backup Strategy: What to Save (and Where)

  • What: website/app files, configs, databases, keys/certs (securely), critical user data.
  • Where: not on the same disk only — use a second server/storage whenever possible.
  • Retention: keep multiple versions (e.g., 7–30 days).
  • Rule of thumb: 3-2-1 (3 copies, 2 different media, 1 offsite).

Linux VPS: Automatic Backups with cron + tar + rsync

This is the most universal “built-in” method for a Linux VPS: create an archive locally and push it offsite via rsync over SSH.

Step 1 — Create a protected backup directory

sudo mkdir -p /backup
sudo chmod 700 /backup

Step 2 — Create a backup script

Create /usr/local/bin/backup.sh:

sudo nano /usr/local/bin/backup.sh

Example script (adjust paths and DB backup to your stack):

#!/usr/bin/env bash
set -euo pipefail

TS="$(date +%F_%H-%M)"
DEST="/backup/backup-${TS}.tar.gz"
LOG="/backup/backup.log"

# Example: database dump (optional)
# mysqldump -u root -p'PASSWORD' --single-transaction --routines --triggers --events yourdb > /backup/db-${TS}.sql

tar -czf "$DEST" \
  /var/www \
  /etc \
  /home

echo "$(date -Is) Created $DEST" >> "$LOG"

Make it executable:

sudo chmod +x /usr/local/bin/backup.sh

Step 3 — Schedule it with cron

sudo crontab -e

Daily backup at 03:00:

0 3 * * * /usr/local/bin/backup.sh >/dev/null 2>&1

Step 4 — Copy backups offsite (recommended)

Never store the only backup on the same VPS. Push to another server/storage (second VPS). Example:

rsync -az /backup/ user@REMOTE_SERVER:/remote-backup/

Add to cron at 03:30:

30 3 * * * rsync -az /backup/ user@REMOTE_SERVER:/remote-backup/ >/dev/null 2>&1

Step 5 — Automatic cleanup (retention)

Delete backups older than 14 days:

find /backup -type f -name "backup-*.tar.gz" -mtime +14 -delete

Add cleanup to cron at 04:00:

0 4 * * * find /backup -type f -name "backup-*.tar.gz" -mtime +14 -delete >/dev/null 2>&1

Restore test (do this periodically)

# List archive contents
tar -tzf /backup/backup-YYYY-MM-DD_HH-MM.tar.gz | head

# Restore a file (example)
tar -xzf /backup/backup-YYYY-MM-DD_HH-MM.tar.gz -C /tmp ./etc/hosts

Windows VPS: Automatic Backups with Windows Server Backup + Task Scheduler

On a Windows VPS, you can use built-in Windows Server Backup (WSB) and schedule jobs via Task Scheduler. This covers files, volumes, and (optionally) System State.

Step 1 — Install Windows Server Backup

Install-WindowsFeature Windows-Server-Backup

Step 2 — Run a backup with wbadmin (example)

Example: backup drive C: to a dedicated backup disk (replace target). For System State, add -systemState where appropriate.

# Example: volume backup
wbadmin start backup -backupTarget:E: -include:C: -quiet

Step 3 — Schedule automatic backups (Task Scheduler)

Create a scheduled task that runs under SYSTEM with highest privileges. Action example:

powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "wbadmin start backup -backupTarget:E: -include:C: -quiet"

Step 4 — Check logs and verify restore readiness

  • Review Windows Server Backup logs and task history.
  • Periodically restore a couple of files to a test folder.
  • Ensure the backup target has enough free space for retention.

Built-in Backup Checklist (Quick)

  • Backups run automatically and produce readable logs.
  • At least one copy is stored offsite (separate server/storage).
  • Retention is enforced (cleanup/rotation).
  • Restore test is performed periodically.
  • Credentials and access to backups are restricted.

Conclusion

Automatic backups using built-in tools are a strong baseline: Linux cron + tar/rsync and Windows Server Backup + Task Scheduler cover most real-world cases. For stable performance and predictable backup windows, run them on a properly sized Linux VPS or Windows VPS with reliable storage on VPS hosting.

Prev