Backup Command Example
Explore how to write Bash commands that archive and copy files to create backups in the home directory. Understand the use of logical operators to combine commands, handle errors, and log success or failure statuses. This lesson helps you automate and monitor backups through scripting techniques.
We'll cover the following...
Backup command
We need an example to consider Bash scripts’ features. Let’s write the command that creates a backup of our photos in the home directory. The command consists of two actions: archiving and copying.
Let’s suppose that we store all our photos in the ~/photo directory. We want to save them in ~/backup. Then, the following command creates an archive of the photos there:
tar -cjf ~/photo.tar.bz2 ~/photo && cp -f ~/photo.tar.bz2 ~/backup
Run the commands discussed in this lesson in the terminal below.
Here, the logical AND ...