Create a Scheduled Linux Backup Script
Regularly scheduled system backups are vital to maintaining users' data. Manual backups are prone to error. Linux provides command-line tools for backing up a user's entire file system. These commands can be combined into a script, which is a file containing a series of commands. This lab will teach you the basics of writing a script in Linux.
Already have an account? Sign In »
Linux scripts are a series of Linux commands executed in succession. When running a series of commands that are used frequently, it is more efficient to combine these strings of commands into a single executable file, called a script. Scripts allow system administrators to save time and remove common errors when executing a particular task. Linux scripts are also useful for giving Linux functionality to users who may not be skilled programmers. These scripts also provide an input gateway into the more complex Linux capabilities you've created.
One good example of the power of Linux scripts is the use of scripts to automate data backups. Backup scheduling establishes time frames to back up users' entire file system. Consistently backing up files is the only way to safeguard a business against data loss. By automating the backups, you will ensure data safety and remove potential errors in the backup process, as well as protecting against user forgetfulness. Depending on your users to back up their data can lead to inconsistent and error-prone backups, and effective system administrators must know how to keep their users' data safe.
In this virtual lab, you will learn how to develop an automated backup in Linux using shell scripting and Crontab. You will write a backup script in Linux and use Linux tools to automate the backing up of users' data.
Understand the scenario: You are the Linux administrator in your organization. Your manager has asked you to create a scheduled backup script that backs up everything in the /home/user1/data directory to a compressed archive file. A backup log must be kept in a separate file that maintains a list of dates on which backups were completed successfully.
Understand your environment: An Ubuntu Linux virtual machine named Ubuntu1 has been created for you.
Create a Backup Script on Ubuntu1:
This virtual lab consists of two steps. In the first step, you will create the Linux script for backing up users' data. You will:
- Create a file system for a sample user.
- Open a Linux text editor for writing the script.
- Use the script to capture the date.
- Use the script to execute the tar command.
- Use the script to create a log of backup dates.
- Make the script executable by all users.
Schedule the Backup Script to Run Automatically:
For the second step of this challenge, you will set your script to run automatically. You will:
- Clear the backup directory of all files.
- Edit the crontab for a user so that the backup script runs at set times.
- Verify your backup script.
Backing up users' data is a critical part of a system administrator's day-to-day tasks. Linux provides many options for backing up data. The most efficient way of using Linux for scheduling backups is by creating a Linux script. This script can be set to run automatically at set times to ensure data safety. This hands-on lab will give you valuable experience creating backup scripts in Linux.
In the "Create a Scheduled Linux Backup Script" virtual lab, you will accomplish the following:
- Write a Linux script using a Linux text editor.
- Add commands to the script to backup user data to a backup directory.
- Write a backup log to keep a record of when data backups occur.
- Set the script to run automatically at set times.
Other Challenges in this series:
- ADVANCED CHALLENGE: Can You Configure Linux Time Sources?
- ADVANCED CHALLENGE: Can You Configure Linux rsyslog Forwarding?