Backup Linux filesystem using Ruby Backup Gem

Introduction

Ruby Backup Gem is a simple backup solution for Unix/Linux operating systems, It helps to back up the file system in the Ruby environment.

It can be used to back up the local filesystem in any virtual servers or physical servers, We have used this in our small production environment running on top of Ubuntu Linux Virtual Private servers.

To make sure to take the regular backup we have a scheduler in place. This helps to back up our critical production environment build with Ruby without having an additional backup solution totally free of cost.

Read more articles about Ruby

Starting Ruby Backup Gem installation

Install with Ruby and its dependencies to run below backup setup. We are not covering “how to install Ruby” in this guide. The Ruby backup gem we are about to install is on our existing development and production servers.

Let’s start to install the Backup gem.

$ sudo gem install backup

Prepare backup config file

Right after the installation, let’s start to generate the config.rb file for backup configuration.

$ backup generate:config

Right in the home directory, we could get a config file in the name config.rb.

/home/sysadmin/Backup/config/config.rb

Configuring Backup

Now let’s configure the backup, for instance, if we need to take the backup for files, database, queue production DB use the following command to create the model file.

$ backup generate:model --trigger production_database_name_here --databases="postgresql" --archives --compressor="gzip" --notifiers="mail"

Edit the files under Backup/config/ and make the required changes.

To check for the config error, use the following command inside the config directory.

$ backup check

That’s all the required configuration.

Back up the file System.

To initiate a manual backup, run the below command with options and arguments.

$ backup perform -t production_database_name_here

This will confirm whether the config works.

Schedule for auto backup.

Now it’s time to automate the Backup using whenever gem

Install the Whenever Gem Using

$ sudo gem install whenever

Configure the whenever gem. First, we need to create a directory named Backup

$ mkdir config && cd ~/home/sysadmin/Backup/config

Then run the command wheneverize to get create the schedule.rb file under /home/sysadmin/Backup/config

$ wheneverize

Add the content to get the scheduler effective

every 1.day, :at => '3:00 am' do
command "/usr/local/bin/backup perform -t database --config-file /root/Backup/config.rb"
command "/usr/local/bin/backup perform -t file_backup --config-file /root/Backup/config.rb"
end

Add the Scheduler to crontab using

$ whenever -w ~/Backup/config/schedule.rb

Then Update the Crontab using the following command,

$ whenever --update-crontab

That’s it we completed with setting up a simple backup solution to back up our Ruby development or production environment using Ruby backup gem.

Conclusion:

A simple backup solution for sites running on the ruby. No need to install with any additional packages except Ruby Backup gem. It takes lesser than 5 minutes to set up a file system backup using Backup gem. Hope this helps you to set up one, your feedbacks are welcome through below comment section.

Exit mobile version