Backup with a Shell Script

You can write a shell script that will create a backup of your system, or specific folder. Let's write one to backup our Pictures folder.

Create Backup folder and Script

backup folder

First, go to your Documents folder and create folder named backups. Next, open the text editor and copy this script into it. Save it as backup in your bin folder.

#!/bin/sh
# Backup Pictures Folder

# What to backup. 
backup_files="/home/ubuntu/Pictures"

# Where to backup to.
dest="/home/ubuntu/Documents/backup"

# Create archive filename.
day=$(date +%A)
hostname=$(hostname -s)
archive_file="$hostname-$day.tgz"

# Print start status message.
echo "Backing up $backup_files to $dest/$archive_file"
date
echo

# Backup the files using tar.
tar czf $dest/$archive_file $backup_files

# Print end status message.
echo
echo "Backup finished"
date

# Long listing of files in $dest to check file sizes.
ls -lh $dest

Execute Backup Script

To run the backup script, in Terminal type:

cd bin
sudo bash backup

It should return that it's completed the backup, and if you check your backup folder, you'll see it!

backup file

You can go futher by backing up your entire Ubuntu system to an external hard drive. There are instructions for that here.

To complete this challenge, upload a screenshot of your backup .tgz file!