By Zelia / Last Updated July 18, 2023

What is Linux system

Linux is a free, open-source operating system kernel that is widely used on a variety of computer systems, including servers, embedded devices and personal computers, etc. Linux systems have several important features:

  • Open source: It is open-source software and you are free to view, modify and distribute the source code.
  • Stable and reliable: It is highly stable and reliable, able to run for long periods of time without the need to reboot.
  • Security: It provides multi-level security measures such as access control, file encryption and network security to protect the system from malicious attacks and data leakage.
  • Flexibility: It is highly flexible and customizable, and can be configured and modified according to your needs, which can meet a variety of different application scenarios.
  • Easy to maintain: It provides a series of tools and command line interface to facilitate system management and maintenance.

linux-backup-to-amazon-s3

Advantages of choosing Amazon S3 as your Linux backup storage

Choosing Amazon S3 as your Linux backup storage has the following advantages:

♦ Security: It provides multiple security measures to protect backup data from unauthorized access and data leakage.

♦ Scalability: It provides highly scalable storage and compute resources that can be automatically scaled up and down according to your needs to meet the growing demand for backup data.

♦ Easy-access: It provides an easy-to-use API and console interface that allows you to easily upload, download and manage backup files.

♦ Cost-effective: Backup to Amazon S3 Linux reduces hardware equipment and maintenance costs while still providing access to secure backup storage services.

Therefore, choosing Amazon S3 as your Linux backup storage is a reliable, secure, efficient, and cost-effective choice for a wide range of backup needs.

How to backup Linux to Amazon S3 step by step

Performing a Linux backup to Amazon S3 involves several steps. Here's a guide to accomplish Linux backup:

Prerequisites for executing Linux backup

  • ssh access to your server
  • sudo permissions
  • an amazon s3 account
  • AWS-CLI installed

Steps to backup Linux server to Amazon S3

1. Configure the S3 storage setting: Set up the s3cmd to use bucket. Type the following command to process:

aws configure

2. Create an S3 bucket in Amazon from command line: Using AWS-CLI, create a bucket to upload files with just one straightforward command:

aws s3 mb s3://myserver_backups

3. Write the backup script: First, you need a place to keep the backups, for example:

mkdir /var/www/_backups

4. Create a backup.sh file in home directory:

#!/bin/sh

THEDBUSER="myDatabaseUsername"

THEDBPW="myDatabasePassword"

THEDATE=`date +%d%m%y%H%M`

# Export all the databases

mysqldump -u $THEDBUSER -p${THEDBPW} --all-databases > /var/www/_backups/dbbackup_${THEDATE}.sql

# Remove backups older than 31 days

find /var/www/_backups/site* -mtime +31 -exec rm {} \;

find /var/www/_backups/apache* -mtime +31 -exec rm {} \;

find /var/www/_backups/db* -mtime +31 -exec rm {} \;

# Export files

tar czf /var/www/_backups/sitebackup_${THEDATE}.tar -C / var/www/docs

# Export the Apache vhosts configuration

tar czf /var/www/_backups/apachebackup_${THEDATE}.tar -C / etc/apache2/sites-available

# Sync to amazon. With the 'delete' option, the files removed from

# /var/www/_backups will be removed from the bucket as well

aws s3 sync /var/www/_backups s3://my-bucket-name –delete

5. Make that script executable with the following command and test it.

chmod +x backup.sh

./backup.sh

6. If all is well, edit your crontab with ‘crontab -e’ and append something like:

0 3 * * * /path/to/backup.sh > /dev/null 2>&1

Conclusion

In conclusion, backing up Linux systems to Amazon S3 provides a reliable and secure solution for protecting your valuable data. The advantages of leveraging Amazon S3 make it an ideal choice for Linux backup storage. By following the outlined steps, you can ensure the accessibility and integrity of their Linux system backups.