Console Login
Home / Blog / Server Administration / Cron, Rsync, and Paranoia: Automated Backup Best Practices for Norwegian SysAdmins
Server Administration 9 views

Cron, Rsync, and Paranoia: Automated Backup Best Practices for Norwegian SysAdmins

@

Stop Trusting Hardware: The Art of Automated Defense

There are two types of system administrators: those who have lost data, and those who will. If you are relying on your hosting provider's RAID controller to save you from a disaster, you are playing Russian Roulette with your business logic. I learned this the hard way in 2008 when a "redundant" array corrupted silently, taking a high-traffic forum down for three days. We were restoring from tape. It was humiliating.

In the Norwegian market, where clients expect stability rivaling the power grid, you cannot afford downtime. Latency to NIX (Norwegian Internet Exchange) means nothing if your database table is empty because of a bad DROP TABLE command. This article isn't about expensive enterprise software suites. It is about using the tools you already have—cron, rsync, and bash—to build a bulletproof backup strategy.

The 3-2-1 Rule: Non-Negotiable

Before we touch the terminal, let's establish the architecture. The 3-2-1 rule is the industry standard for a reason:

  • 3 Copies of Data: Production, Local Backup, Off-site Backup.
  • 2 Different Media: Don't keep backups on the same physical disk partition.
  • 1 Off-site: If the data center in Oslo floods, your data must exist in Bergen or Trondheim (or at least a different facility).

Scripting the Solution

We are going to write a script that runs nightly. It will dump the MySQL database, compress the web files, and push them to a remote server. We assume you are running CentOS 5 or Ubuntu 10.04 LTS.

1. The Database Dump

Never copy raw MySQL files (`/var/lib/mysql`) while the server is running. You will get inconsistent data. Use `mysqldump`. We lock tables briefly to ensure consistency.

#!/bin/bash

# Configuration
DB_USER="root"
DB_PASS="StrictPassword123"
BACKUP_DIR="/var/backups/daily"
DATE=$(date +"%Y-%m-%d")

# Ensure backup dir exists
mkdir -p $BACKUP_DIR

# Dump all databases
mysqldump -u $DB_USER -p$DB_PASS --all-databases --opt | gzip > $BACKUP_DIR/db_dump_$DATE.sql.gz

2. The File System Archive

Next, we archive the web root. We use tar with gzip compression. Note the use of --exclude to skip cache files which just waste I/O cycles and bandwidth.

# Archive Web Files
tar -czf $BACKUP_DIR/files_$DATE.tar.gz /var/www/html --exclude=*/cache/*

3. Sending Off-Site (The Critical Step)

This is where CoolVDS shines. Because we use unthrottled 100Mbit ports and high-performance RAID-10 SAS storage, sending large backup files between instances is fast. If you are using a secondary CoolVDS VPS as your backup vault, transfer speeds are negligible on the internal latency.

We use rsync over SSH. It is encrypted, and unlike FTP, it handles network drops gracefully.

# Sync to Remote Backup Server
rsync -avz -e "ssh -p 22" $BACKUP_DIR/ [email protected]:/home/remote_user/backups/
Pro Tip: Use SSH keys (`ssh-keygen`) for password-less authentication so Cron can run this script without human intervention. Never hardcode SSH passwords in scripts.

The Compliance Angle: Datatilsynet is Watching

Hosting in Norway brings specific legal responsibilities under Personopplysningsloven (Personal Data Act). You cannot simply dump your customer data onto a cheap FTP server in the United States without navigating a legal minefield regarding Safe Harbor.

By keeping your primary server and your backup node within CoolVDS's Norwegian or European infrastructure, you simplify compliance. Data sovereignty is not just a buzzword; it is a legal requirement for many of our clients handling medical or financial data.

Automating with Cron

A script is useless if you forget to run it. Add it to your crontab. Run it at 3:00 AM when traffic is lowest.

0 3 * * * /bin/bash /root/scripts/nightly_backup.sh >> /var/log/backup.log 2>&1

Performance: Why I/O Matters

Backups are I/O intensive. `tar` and `gzip` eat CPU and Disk reads. On budget hosts overselling their hardware, running a backup script causes "CPU Steal" and makes your website lag for users. This is where the underlying infrastructure counts.

At CoolVDS, we utilize Hardware RAID-10 with enterprise SAS drives (and SSD caching on select nodes). This provides the Input/Output Operations Per Second (IOPS) necessary to read gigabytes of data for backup without choking the live web server. If your current host slows to a crawl every night at 3 AM, check your I/O wait times with `top`.

Feature CoolVDS Architecture Budget VPS
Storage RAID-10 SAS/Enterprise SSD Single SATA Drive (Risk!)
Virtualization KVM (Kernel-based Virtual Machine) OpenVZ (Oversold resources)
Network Low latency to Oslo Routed via Frankfurt/London

Final Thoughts

Automated backups are your insurance policy. They don't need to be complex, but they need to be consistent. Don't wait for a drive failure or a hacker to teach you this lesson.

If you need a reliable destination for your off-site backups, or a primary server that doesn't choke during data compression, spin up a high-performance instance with us. Don't let slow I/O kill your SEO or your sleep schedule.

/// TAGS

/// RELATED POSTS

Surviving the Spike: High-Performance E-commerce Hosting Architecture for 2012

Is your Magento store ready for the holiday rush? We break down the Nginx, Varnish, and SSD tuning s...

Read More →

Automate or Die: Bulletproof Remote Backups with Rsync on CentOS 6

RAID is not a backup. Don't let a typo destroy your database. Learn how to set up automated, increme...

Read More →

Nginx as a Reverse Proxy: Stop Letting Apache Kill Your Server Load

Is your LAMP stack choking on traffic? Learn how to deploy Nginx as a high-performance reverse proxy...

Read More →

Apache vs Lighttpd in 2012: Squeezing Performance from Your Norway VPS

Is Apache's memory bloat killing your server? We benchmark the industry standard against the lightwe...

Read More →

Stop Guessing: Precision Server Monitoring with Munin & Nagios on CentOS 6

Is your server going down at 3 AM? Stop reactive fire-fighting. We detail the exact Nagios and Munin...

Read More →

The Sysadmin’s Guide to Bulletproof Automated Backups (2012 Edition)

RAID 10 is not a backup strategy. In this guide, we cover scripting rsync, rotating MySQL dumps, and...

Read More →
← Back to All Posts