0

I am having difficulty trying to backup my 'my_work' directory into my destination 'Backup' directory. I tried running the script, but it does not seem to work. This is the script that I have written :

#!/bin/bash

SRCDIR="/home/student/Documents/my_work/"
DESTDIR="/home/student/Backups/"
FILENAME=backup1-$(date +%-Y%-m%-d)-$(date +%-T).tgz 
tar --create --gzip --file=$DESTDIR $FILENAME $SRCDIR

This is the output I received :

tar: backup1-201576-10\:24\:17.tgz: Cannot stat: No such file or directory
tar: Removing leading '/' from member names
tar (child): /home/student/Backups/: 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

I can't seem to find a solution to this, please help

1

1 Answer 1

2

Just make a subtle change in your script:

Change

tar --create --gzip --file=$DESTDIR $FILENAME $SRCDIR

to

tar --create --gzip --file=$DESTDIR$FILENAME $SRCDIR

Notice there is no space between $DESTDIR and $FILENAME. To suppress tar: Removing leading '/' from member names, you may use the -P flag cautiously.

Also, it'd be nice to replace colons in the filename with underscores or dashes. Colon is a reserved character that is also used in PATH and may cause confusion.

Sign up to request clarification or add additional context in comments.

1 Comment

Suggesting quotes around the variable expansions would also be a good idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.