Skip to content

Setup — Backup Script

Create the project directory and verify rsync and tar work on your system.

Project Structure

mkdir -p ~/projects/backup-script
cd ~/projects/backup-script
touch backup.sh
chmod +x backup.sh

Create a Test Source Directory

mkdir -p ~/projects/backup-script/test_source/subdir
echo "Hello, backup!" > ~/projects/backup-script/test_source/file1.txt
echo "Config data"   > ~/projects/backup-script/test_source/config.conf
echo "Nested file"   > ~/projects/backup-script/test_source/subdir/nested.txt

Confirm the structure:

find ~/projects/backup-script/test_source -type f
/home/user/projects/backup-script/test_source/file1.txt /home/user/projects/backup-script/test_source/config.conf /home/user/projects/backup-script/test_source/subdir/nested.txt

Verify rsync is Available

rsync --version | head -1
rsync version 3.2.7 protocol version 31

If rsync is not installed:

# Debian/Ubuntu
sudo apt install rsync

# RHEL/Fedora
sudo dnf install rsync

# macOS
brew install rsync

Verify tar and gzip

tar --version | head -1
gzip --version | head -1
tar (GNU tar) 1.34 gzip 1.12

Test an rsync Backup Manually

mkdir -p /tmp/backup_test_dest
rsync -av ~/projects/backup-script/test_source/ /tmp/backup_test_dest/
sending incremental file list ./ config.conf file1.txt subdir/ subdir/nested.txt sent 312 bytes received 92 bytes 808.00 bytes/sec total size is 43 speedup is 0.11

Test a tar Archive Manually

tar -czf /tmp/test_archive.tar.gz -C ~/projects/backup-script test_source/
ls -lh /tmp/test_archive.tar.gz
-rw-r--r-- 1 user user 612 Jan 15 09:00 /tmp/test_archive.tar.gz

Extract it back to verify:

tar -tzf /tmp/test_archive.tar.gz
test_source/ test_source/file1.txt test_source/config.conf test_source/subdir/ test_source/subdir/nested.txt

Test sha256sum

sha256sum /tmp/test_archive.tar.gz
d4e8a3... /tmp/test_archive.tar.gz
# Verify the checksum
sha256sum /tmp/test_archive.tar.gz > /tmp/test_archive.tar.gz.sha256
sha256sum --check /tmp/test_archive.tar.gz.sha256
/tmp/test_archive.tar.gz: OK

requirements | implementation