
With the complexity and moving pieces involved in today's applications and computing, failure is inevitable. The Cybersecurity and Infrastructure Security Agency (CISA) recommends that individuals and businesses use what is commonly referred to as a 3-2-1 strategy.
This case study uses a Ubuntu 20.04 LTS server as the base operating system. Deploy a new Vultr Ubuntu 20.04 (x64) cloud server using the type of configuration that best suits the needs of the environment you support. Ensure to deploy/locate the server in any datacenter except New York (NJ). This ensures two distinctly different locations of the data and backup files. Also, ensure to check "Enable Auto Backups" in the server configuraiton. Throughout this document, the server name is apphost. After deploying apphost update the server according to the Ubuntu best practices guide.
After deploying apphost, add a user that performs the tasks of 3-2-1 backup. This document names the user beepbeep (as in backing up) because backup is often a reserved word in many operating systems and languages and, therefore, should not be used. The user beepbeep should only be performing automated tasks, so after creating it, lock the account, preventing it from logging in. To create the account and then lock it, run:
To perform the 3-2-1 backup, create 3 supplemental directories. These directories are for:
To create the application/backup directory, run:
To create the directory to hold the backups, run:
To create the directory to hold the logs, run:
This guide stores the off-site data in Vultr Object Storage. Vultr Object Storage uses S3 protocols. This 3-2-1 document uses awscli to communicate and store the off-site backup.
To install awscli run:
This downloads the package and supplemental files, unzips them, installs them, and removes the original files.
MariaDB is one of the most common database platforms. This document uses a demonstration database running on MariaDB to highlight the 3-2-1 idea by backing up the database both locally and off-site. To install the latest version of MariaDB, update the repository by running:
After updating the repository, install MariaDB by running:
After installation, enable MariaDB to start on boot by running:
Now, secure the database. Run the built-in utility provided by MariaDB:
There are a series of questions. To ensure an optimal and secure database answer them as follows:
After installing and configuring MariaDB, create and populate a sample database. The following steps download, extract, import, and then delete the file associated with the sample database:
Now that there is a populated database, create a restricted user to complete the 3-2-1 backup. Lock this user down, only giving permission to backup the data and not alter it. To do this, access the MariaDB console, create and then grant specific permissions to the user. Also, lock the account to only access the database from localhost. Carry out these tasks by running:
Note in the above, the user has a username of sqlbackuser and password of Password123!. Best practice uses a strong, random password in place of the above password. You can randomly generate a long, secure password online.
To meet the third point of the 3-2-1 backup strategy, store files in a secondary, off-site location. To do this, create Vultr Object Storage. Label the object storage appropriately. After creating the object storage, take note of the Secret Key and Access Key.
Now all the components are in place, create the configurations to support the solution. To do this, from the root account, use the su command to log in to the beepbeep account (as it cannot log in from a command prompt, based on the account creation). From the root prompt, run:
To confirm successful login as beepbeep the command prompt reads:
To configure awscli, type aws configure at the prompt (logged in as beepbeep). It asks four questions:
After you enter these four values, awscli creates multiple configuration files used by the program and the user.
The database backup script needs to know the username and password to use when running. These credentials live in a file called .my.cnf, located in the root directory of the user running the backup command. To edit this file, first ensure you are in the root of the beepbeep users' home directory, logged in as the beepbeep user. You can check the directory by typing pwd and it should return /home/beepbeep/. You can check the user by typing whoami and it should return beepbeep. After confirming these two settings, create the file by typing:
After the editor is open, add the following lines to the file (ensuring to change the password to the one you used above):
Save the file by pressing Ctrl+X and then pressing Y and Enter.
Now, secure the file by changing the permissions to only allow beepbeep to read it by running:
Now all the pieces are in place for the actual backup to occur, create the backup script. Store the backup script in the directory created at the beginning. Still logged in as the beepbeep user, change the working directory by typing:
After changing to this directory, create the backup script called backup.sh by typing:
The contents of this file should contain:
The variables in the top section control the way the backup script works. Make sure to change the DBNAME to the name of the database used in production.
After creating the script, it still does not have the ability to execute on behalf of the beepbeep user. Change the file to allow the user to execute the script by running:
After changing the execution bit on the file, you can type exit to log out of the beepbeep user session and return back to the root user's command prompt.
As root, create a Cron job:
Inside the file enter the following:
The '32 05denotes the script runs daily at 05:32 (local time to the server), and the* * *denotes it runs every day of every week of every month. Thebeepbeepis the user who runs the command, and the command is at the end. The line ends with> /dev/null 2>&1` to essentially discard any extra output the file produces.
The worst thing to do is create a 3-2-1 backup strategy and not actually test it. All too often, with backup strategies, it's "set it and forget it". If you do that with the backup the day you need it, the last successful backup won't contain what you need. Check the machine backup. Ensure it restores successfully. Open local archival backups. Make sure the data backed up is inside those files. Open the remote/off-site backup. Make sure the data is also in those files. The worst feeling is when you need a backup and don't have it or the files you need are missing or not there.
By deploying a virtual host with backups enabled, you carry out the easiest part of the backup. You can restore the system backup using the Vultr Console. The second part of backup is backing up files. Setting a routine job to run at set intervals accomplishes this task. Reassurance this is successful comprises opening the backup files and finding the data required. After you have the system backed up, and the files backed up as well, store another copy of the files off-site. Use a technology like Vultr Object Storage, giving you a second copy at a second location, should a catastrophic failure occur. This strategy, known as the 3-2-1 backup strategy, one day, just might come in handy.
0 Comments
Be the first to comment and share your perspective with the community.