Introduction

This guide provides step-by-step instructions on automating ArangoDB installations, updates, and backups using Shell scripts, from start to finish.

Installing the Latest Version of ArangoDB on Ubuntu 18.04

Visit the ArangoDB website to download the latest version of the database. As of this guide, the current version is 3.6.5-1. Below is a script to install and configure ArangoDB on an AWS EC2 server.

Important Precautions

Ensure that you stop the ArangoDB service and switch your application to maintenance mode before proceeding.

#!/bin/bash
sudo systemctl stop arangodb3.service
sudo cp -r /etc/arangodb3/ ~/arango-config-backup
curl -OL https://download.arangodb.com/arangodb36/DEBIAN/Release.key
sudo apt-key add - < Release.key
echo 'deb https://download.arangodb.com/arangodb36/DEBIAN/ /' | sudo tee /etc/apt/sources.list.d/arangodb.list
sudo apt-get update
sudo apt-get install arangodb3=3.6.5-1
sudo sed -i "s+endpoint = tcp://127.0.0.1:8529+endpoint = tcp://0.0.0.0:8529+g" /etc/arangodb3/arangod.conf
sudo systemctl enable arangodb3.service
sudo systemctl start arangodb3.service
sudo systemctl status arangodb3.service
sudo sysctl -w "vm.max_map_count=1024000"

Backup and Upload ArangoDB to Amazon S3

This script handles the backup of ArangoDB and its upload to Amazon S3 storage.

#!/bin/sh
NOWDATE=$(date +%Y-%m-%d)
DIRNAME="Your directory name"
BUCKETNAME="Your bucket name in S3"
DATABASENAME="Your database name"
mkdir -p "/home/ubuntu/backup/$DIRNAME"
arangodump --server.endpoint tcp://127.0.0.1:8529 --server.username root --server.password 'yourpassword' --server.database $DATABASENAME --output-directory "/home/ubuntu/backup/$DIRNAME/" --compress-output --overwrite
tar -czvf /home/ubuntu/backup/$NOWDATE-$DATABASENAME-backup.tar.gz -C /home/ubuntu/backup/$DIRNAME .
aws s3 cp /home/ubuntu/backup/$NOWDATE-$DATABASENAME-backup.tar.gz  s3://$BUCKETNAME/dbbackup/
aws s3 rm s3://$BUCKETNAME/dbbackup/$LASTDATE-$DATABASENAME-backup.tar.gz
rm -rf /home/ubuntu/backup/$NOWDATE-$DATABASENAME-backup.tar.gz
rm -rf /home/ubuntu/backup/$DIRNAME/*

Restore ArangoDB from Amazon S3

The following script details the procedure to restore ArangoDB from a backup stored on Amazon S3.

#!/bin/sh
DIRNAME="Your directory name"
BUCKETNAME="Your bucket name in S3"
DATABASENAME="Your database name"
read -p "Please enter file date (YYYY-MM-DD):" FILE_NAME
aws s3 cp s3://$BUCKETNAME/dbbackup/$FILE_NAME-$DATABASENAME-backup.tar.gz /home/ubuntu/backup/
tar -xzvf /home/ubuntu/backup/$FILE_NAME-$DATABASENAME-backup.tar.gz -C /home/ubuntu/backup/$DIRNAME
arangorestore --server.endpoint tcp://127.0.0.1:8529 --server.username root --server.password 'yourpassword' --server.database $DATABASENAME --input-directory "/home/ubuntu/backup/$DIRNAME" --create-database
rm -rf /home/ubuntu/backup/$FILE_NAME-$DATABASENAME-backup.tar.gz
rm -rf /home/ubuntu/backup/$DIRNAME/*

Automating Backups with Systemd Services

Automate your backup tasks with systemd services for better management and reliability.

  1. Navigate to /etc/systemd/system and create backup.service and backup.timer.
  2. Configure the backup service file to run

the backup script. 3. Set the timer to execute the backup script at a specified time.

[Unit]
Description=Schedule ArangoDB backup service
[Timer]
OnCalendar=*-*-* 02:30:00
Unit=backup.service
[Install]
WantedBy=multi-user.target
[Unit]
Description=Run ArangoDB backup script
[Service]
ExecStart=/bin/bash /home/ubuntu/backup/backup.sh

After setting up these files, manage the services as follows:

sudo systemctl daemon-reload
sudo systemctl start backup.timer
sudo systemctl status backup.timer

With these steps, you will have a fully automated backup system on your server.