LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Backup Script error (https://www.linuxquestions.org/questions/linux-newbie-8/backup-script-error-946849/)

mogleyzw 05-25-2012 11:10 AM

Backup Script error
 
Hi,

I am trying to write a backup script but keep getting an error. Here is my code

Code:

#!/bin.bash

backup_files=/home
backup_dir=/backup
date=$(date +%d-%m-%Y)
archive_files="$date.tgz"

mkdir backup

echo "backing up $backup_files to $archive_files"

tar czvf $backup_dir/$archive_files $backup_files

echo "backup complete"

After I run the program I get the following messeges.

Quote:

/home/
: No such file or directory
tar: /home/user/
/home/user/.bash_history
Error not recoverable: exiting now
/home/user/backup.sh
I am using a virtual device with ubuntu running and there but there is nothing on it. Is that why I am getting that error??

Thanks in advance.

mogleyzw 05-25-2012 11:28 AM

I just realized this is in the wrong place, sorry.

Ser Olmy 05-25-2012 11:30 AM

Quote:

Originally Posted by mogleyzw (Post 4687497)
Hi,

I am trying to write a backup script but keep getting an error. Here is my code

Code:

#!/bin.bash

backup_files=/home
backup_dir=/backup
date=$(date +%d-%m-%Y)
archive_files="$date.tgz"


OK, at this point $backup_files is "/home", $backup_dir is "/backup" and $archive_files is "25-05-2012.tgz". Then you proceed to do:
Quote:

Originally Posted by mogleyzw (Post 4687497)
Code:

mkdir backup

Unless the current directory is /, the above does nothing useful.
Quote:

Originally Posted by mogleyzw (Post 4687497)
Code:

echo "backing up $backup_files to $archive_files"

tar czvf $backup_dir/$archive_files $backup_files

echo "backup complete"


You're running tar czvf /backup/25-05-2012.tgz /home, which result in:
Code:

/home/
: No such file or directory
tar: /home/user/
/home/user/.bash_history
Error not recoverable: exiting now
/home/user/backup.sh

The "Error not recoverable" message is the real problem, and my guess is it appears because the directory /backup doesn't exist.

mogleyzw 05-25-2012 11:45 AM

Thanks for that I kind of get what you mean.

How would I change it so it backs up the "/home" directory.

Ser Olmy 05-25-2012 11:55 AM

All I did was add the missing slash to "mkdir /backup" (or even better, "mkdir $backup_dir", since you're already using a variable to hold the directory name).

mogleyzw 05-25-2012 12:01 PM

Wow thank you that worked :)

mogleyzw 05-25-2012 12:08 PM

Sorry one last thing, when I tested it, it work but I can not find where the backup is. I was under the impression it would go into the folder backup with the date as the file name.

mogleyzw 05-25-2012 12:18 PM

Don't worry found it "ls -l /backup/"

Thanks for all the help.


All times are GMT -5. The time now is 02:21 PM.