Forumgarden backup arrangements

Post Reply
User avatar
spot
Posts: 41339
Joined: Tue Apr 19, 2005 5:19 pm
Location: Brigstowe

Forumgarden backup arrangements

Post by spot »

I'm currently responsible for backing up five servers. It might be a good idea to write up my current process here.

DR;TL: the text below shows commands and prices for using Contabo storage with 3x RAID redundancy: $2 a month for 250GB of user data.

There's this thing called the cloud. If you have an account with a company which owns a bit of the cloud, you can run processes locally which create, amend and delete remote resources for which you make payment.

The granularity of payment differs from one supplier to another. Amazon Web Services (AWS) for instance bills an agreed amount per minute - or second, I'm not sure - which means you can (if you need one) create a virtual computer - a 500 cpu resource with 8TB of memory, say - and run your process for quarter of an hour and then delete the instance. Your monthly bill might show that later as $15. That's cheaper than owning one. Right, I checked... today you can rent a virtual 448 core CPU with 6TB of memory and a 100 GBit network connection for $54.60 an hour, billed by the second. Or you can make a dozen smaller machines for the same price. So long as you destroy them after, they're comparatively cheap.

And AWS storage for data backups is $5 a month per 100GB with 1GB granularity.

Contabo turns out to be cheaper for data backups. Contabo charges $2 a month per 250GB, with 250GB and 1 month granularity, up to an account limit of 240TB. I'm paying for one unit. That one unit is where the data from all five of the machines I'm handling are backed up.

I'm using "block storage", which is fine for few large files. It's awful for storing a file system one file at a time - for that you need a file system backup plan. AWS has one, for example. I'm not sure what Contabo offers in that regard.

So, on each machine I'm backing up, I have a script which gathers all the data into one place and merges it into a single backup file, compresses the file, encrypts the file, and copies to my Contabo block storage account. As they accumulate I'll work out an automated deletion process which keeps just a few long-term and a few recent copies, I've not done that yet.

Code: Select all

#!/bin/bash
# remote archive to contabo, requires:
#     ~/.config/rclone/rclone.conf     (contabo permission)
#     .my.cnf                          (mysql permission)
#     passphrase                       (gpg permission)
#     contabo-backup.sh                (this script)
# jh april 2020
if (( $EUID != 0 )); then
    echo "Please run as root!"
    exit
fi
cd /root/contabo
ARCHIVE=$(</etc/hostname)
BACKDIR=$ARCHIVE.Back.$(date "+%Y.%m.%d-%H.%M.%S")
echo "Contabo archive $BACKDIR started"
mkdir /tmp/$BACKDIR
service apache2 stop
echo "apache down"
date +%T
mysqldump --all-databases >/tmp/$BACKDIR/$ARCHIVE.sql
service apache2 start
date +%T
echo "apache back"
rsync -a /usr/local/bin /usr/local/sbin /var/www /etc /root /tmp/$BACKDIR
tar -cJ --exclude tmp/$BACKDIR/root/.gnupg/* -f $BACKDIR.txz -C / tmp/$BACKDIR
rm -rf /tmp/$BACKDIR
gpg --cipher-algo aes256 --output $BACKDIR.txz.gpg --passphrase-file ./passphrase --batch --yes --symmetric $BACKDIR.txz
rm $BACKDIR.txz
rclone sync -P $BACKDIR.txz.gpg eu2:private/$ARCHIVE --s3-no-head
rm $BACKDIR.txz.gpg
date +%T
echo "Contabo archive $BACKDIR completed"
All the data is gathered under a temporary directory. "tar -cJ -f" uses x-compression (the "J") to create ("c") a file ("f"). "gpg" outputs a symmetric-encrypted file using a passphrase. "rclone" copies it into rented Contabo storage under my account.

That runs from /etc/cron.weekly

To get the data restored, I download the backup file to the local machine and:

Code: Select all

gpg -o example.com.Back.2022.04.14-19.19.41.txz --passphrase-file ./passphrase --batch -d example.com.Back.2022.04.14-19.19.41.txz.gpg
unxz example.com.Back.2022.04.14-19.19.41.txz
tar xf example.com.Back.2022.04.14-19.19.41.tar
The -d option in gpg decrypts the specific backup file using the same passphrase it was encrypted with. "unxz" decompresses the decrypted file. "tar x" expands the tar file to recreate the temporary directory, retrieving all the selected files.

It took me a while to work all that out. This thread will be a helpful reminder after I've forgotten stuff.
Nullius in verba ... ☎||||||||||| ... To Fate I sue, of other means bereft, the only refuge for the wretched left.
When flower power came along I stood for Human Rights, marched around for peace and freedom, had some nooky every night - we took it serious.
Who has a spare two minutes to play in this month's FG Trivia game! ... My other OS is Slackware.
User avatar
spot
Posts: 41339
Joined: Tue Apr 19, 2005 5:19 pm
Location: Brigstowe

Re: Forumgarden backup arrangements

Post by spot »

The other thing which might be useful is a VPS (Virtual Private Server), while I'm on the subject.

https://www.ionos.co.uk/servers/vps is the cheapest I've seen. £1.20 a month ($1.60) including taxes, one complete online linux server with root access, nobody else on it unless you invite them. That's around the same price my electricity costs to keep a Raspberry Pi permanently online at 3.5W, but with RAID drive security and commercially reliable availability.
Nullius in verba ... ☎||||||||||| ... To Fate I sue, of other means bereft, the only refuge for the wretched left.
When flower power came along I stood for Human Rights, marched around for peace and freedom, had some nooky every night - we took it serious.
Who has a spare two minutes to play in this month's FG Trivia game! ... My other OS is Slackware.
User avatar
spot
Posts: 41339
Joined: Tue Apr 19, 2005 5:19 pm
Location: Brigstowe

Re: Forumgarden backup arrangements

Post by spot »

This is quite attractive too, for anyone interested. They're called Hetzner and I quite like the interface, having registered there yesterday.

This is a test VPS server for $6 a month, located in Helsinki. 4GB memory, 2 Xeon cores at 3GHz, 40GB SSD. I quite like being able to offload the firewall to their network infrastructure, I've not seen that elsewhere.


Screenshot_2023-03-18_11-35-14.png
Screenshot_2023-03-18_11-35-14.png (218.66 KiB) Viewed 672 times

Code: Select all

root@pensans:/var/log# free
               total        used        free      shared  buff/cache   available
Mem:         3927524      178416     3566208        3184      182900     3536320
Swap:        4095996           0     4095996
root@pensans:/var/log# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs          tmpfs     384M  536K  384M   1% /run
/dev/sda1      ext4       38G  5.8G   31G  16% /
tmpfs          tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs          tmpfs     5.0M     0  5.0M   0% /run/lock
/dev/sdb       ext4       19G   24K   18G   1% /mnt/HC_Volume_29437363
/dev/sda15     vfat      121M  142K  120M   1% /boot/efi
tmpfs          tmpfs     384M     0  384M   0% /run/user/1000
root@pensans:/var/log# service --status-all | grep +
 [ + ]  apache2
 [ + ]  atd
 [ + ]  cloud-config
 [ + ]  cloud-final
 [ + ]  cloud-init
 [ + ]  cloud-init-local
 [ + ]  cron
 [ + ]  dbus
 [ + ]  kmod
 [ + ]  mariadb
 [ + ]  networking
 [ + ]  ntp
 [ + ]  procps
 [ + ]  qemu-guest-agent
 [ + ]  resolvconf
 [ + ]  rsyslog
 [ + ]  ssh
 [ + ]  udev
root@pensans:/var/log#
Nullius in verba ... ☎||||||||||| ... To Fate I sue, of other means bereft, the only refuge for the wretched left.
When flower power came along I stood for Human Rights, marched around for peace and freedom, had some nooky every night - we took it serious.
Who has a spare two minutes to play in this month's FG Trivia game! ... My other OS is Slackware.
User avatar
spot
Posts: 41339
Joined: Tue Apr 19, 2005 5:19 pm
Location: Brigstowe

Re: Forumgarden backup arrangements

Post by spot »

Code: Select all

root@forumgarden:~# neofetch 
       _,met$$$$$gg.          root@forumgarden.com 
    ,g$$$$$$$$$$$$$$$P.       -------------------- 
  ,g$$P"     """Y$$.".        OS: Debian GNU/Linux 11 (bullseye) x86_64 
 ,$$P'              `$$$.     Host: Droplet <removed> 
',$$P       ,ggs.     `$$b:   Kernel: 5.10.0-21-amd64 
`d$$'     ,$P"'   .    $$$    Uptime: 224 days, 9 hours, 21 mins 
 $$P      d$'     ,    $$P    Packages: 847 (dpkg) 
 $$:      $$.   -    ,d$$'    Shell: bash 5.1.4 
 $$;      Y$b._   _,d$P'      Resolution: 1024x768 
 Y$$.    `.`"Y$$$$P"'         CPU: DO-Regular (1) @ 2.294GHz 
 `$$b      "-.__              Memory: 1213MiB / 1983MiB 
  `Y$$
   `Y$$.                                              
     `$$b.                                            
       `Y$$b.
          `"Y$b._
              `"""

root@forumgarden:~# ls -ls
      0 -rw-r--r-- 1 root root          0 Nov  7 20:33 extracted
6999952 -rw-r--r-- 1 root root 7167946097 Nov  7 20:34 forumgarden.com.178.62.85.48.Back.2023.11.07-20.10.22.tar.zst.gpg
1494828 -rw-r--r-- 1 root root 1530699315 Nov  7 20:34 forumgarden.com.sql
      0 -rw-r--r-- 1 root root          0 Nov  7 20:34 gpg-built
      0 -rw-r--r-- 1 root root          0 Nov  7 20:34 now-offsite
      0 -rw-r--r-- 1 root root          0 Nov  7 20:34 touched


root@forumgarden:~#


[/quote]
Nullius in verba ... ☎||||||||||| ... To Fate I sue, of other means bereft, the only refuge for the wretched left.
When flower power came along I stood for Human Rights, marched around for peace and freedom, had some nooky every night - we took it serious.
Who has a spare two minutes to play in this month's FG Trivia game! ... My other OS is Slackware.
Post Reply

Return to “Computers Internet”