Welcome to the Linux Foundation Forum!

An issue with tar

Trying to make a simple backup script that will tar at the end

Script:

!/bin/bash

What to back up

backup_files="home etc root var usr/local/bin usr/local/sbin srv opt "

Where

dest="/home/backup"

Create

day=$(date +%A)
hostname=$(hostname -s)
archive=$hostname-$day.tgz

Print start

echo "Backing up system stand by"
date
echo

Tar command

tar czf $dest/$archive_file $backup_files

Print end

echo
echo "Back up finished Thank you for your patience"
date

End of script

Results when ran
Backing up system stand by
Fri Sep 10 03:32:15 UTC 2021

tar: home: Cannot stat: No such file or directory
tar: etc: Cannot stat: No such file or directory
tar: root: Cannot stat: No such file or directory
tar: var: Cannot stat: No such file or directory
tar: usr/local/bin: Cannot stat: No such file or directory
tar: usr/local/sbin: Cannot stat: No such file or directory
tar: srv: Cannot stat: No such file or directory
tar: opt: Cannot stat: No such file or directory
tar (child): /home/backup/: Cannot open: Is a directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

Back up finished Thank you for your patience
Fri Sep 10 03:32:15 UTC 2021

What is the issue?

Categories

Upcoming Training