Operating System - Linux
1752812 Members
5915 Online
108789 Solutions
New Discussion юеВ

backup & restore user home directory include hidden files

 
SOLVED
Go to solution
'chris'
Super Advisor

backup & restore user home directory include hidden files

hi

I'm looking for simple bash scripts running from the desktop:

1.) backup the user home directory include all hidden files:

tar cvzf /save/user.tar.gz /home/user

2.) restore from the backup /save/user.tar.gz

cd /home/user
tar xvzf /save/user.tar.gz; cd -
26 REPLIES 26
Steven Schweda
Honored Contributor
Solution

Re: backup & restore user home directory include hidden files

Is there a question in there?

> [...] running from the desktop:

Define "the desktop".

> tar c[...] /home/user

You may save yourself some work later if you
avoid specifying an absolute path when you
create your archive. For example:

cd /home
tar c[...] user

cd /home
tar x[...]

GNU "tar" has enough options to let you
recover from many kinds of unwise usage, but
why make more work for yourself than you need
to?
'chris'
Super Advisor

Re: backup & restore user home directory include hidden files

Thx I have created 2 scripts and these scripts should be launched as a normal user directly from a Desktop.

1.) Backup script:

#! /bin/bash
echo 'Backup user home dir'
cd /home
tar cvzf /home/user/save/backup.tar.bz2 $HOME

2.) Restore script:

#! /bin/bash
echo 'Restore user home dir'
cd /home
tar xvzf /home/user/save/backup.tar.bz2

Backup seems to work well, but if I try to restore I get this problem:

# sh restore
Restore user home dir
tar (child): /home/user/save/backup.tar.bz2: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now





Steven Schweda
Honored Contributor

Re: backup & restore user home directory include hidden files

> tar xvzf /home/user/save/backup.tar.bz2

I normally write for old "tar" programs, so I
normally make my own compression pipelines,
so I know nothing, but doesn't "-z" imply the
use of gzip, not bzip2? I don't know what
all these programs will do is you give them
inappropriate file-name suffixes.

http://www.gnu.org/software/tar/manual/

As I read it, "-a" ("--auto-compress") might
be more flexible.

> Backup seems to work well, [...]

Evidence?

What's in "/home/user/save/"? With my weak
psychic powers, I can't see it from here.
Viktor Balogh
Honored Contributor

Re: backup & restore user home directory include hidden files

Hi Chris,

I think it would be a better idea to save the backup outside of the home dir (which is also the subject of the backup) By this you would avoid backing up the already-created backups. What do you think?

Regards,
Viktor
****
Unix operates with beer.
Viktor Balogh
Honored Contributor

Re: backup & restore user home directory include hidden files

I meant this line in your latest script:

tar cvzf /home/user/save/backup.tar.bz2 $HOME

****
Unix operates with beer.
'chris'
Super Advisor

Re: backup & restore user home directory include hidden files

These scrips should run by normal non-root user.
I've setup permissons in /save directory for a normal non-root user.

I changed to tar.gz and it should backup outside of the home dir:

backup:

tar cvzf /save/backup.tar.gz $HOME

restore:

tar xvzf /save/backup.tar.gz


Now, if I try to restore using:

tar xvzf /save/backup.tar.gz

then the extra /home/user/home/user will be created, instead of extracting directly into /home/user/*.

Howto solve this problem?


Steven Schweda
Honored Contributor

Re: backup & restore user home directory include hidden files

> tar cvzf /save/backup.tar.gz $HOME

Should we non-psychics know what "$HOME" is
in this situation?

> Now, if I try to restore using:

Starting where, exactly?

pwd

> Howto solve this problem?

Read previous replies? Read the "tar"
documentation?

Also potentially useful:

man basename
'chris'
Super Advisor

Re: backup & restore user home directory include hidden files

Sorry for misunderstanding and pls let explain:

$HOME is home directory, it's dynamic.

It does the same like:

tar cvzf /save/backup.tar.gz /home/user

on my debian squeeze.

I try to restore, inside from /home/user, because I'd like to do it as a normal non-root user.

I think, running from / as a root user shouldn't be a problem.


Perhaps I'll try completely other solution:

copy ALL from /home/user/* into /save/*

and runnig this script outside of home dir:

#! /bin/bash
echo 'restore user settings'
cd /save
find . -print | cpio -dumpv /home/user








Steven Schweda
Honored Contributor

Re: backup & restore user home directory include hidden files

> $HOME is home directory, it's dynamic.

Thanks for the explanation, but I think that
I understood that much. However, you demand
that I assume/guess that its value is
"/home/user/" in things like:

> then the extra /home/user/home/user will be
> created [...]

You're the one who wants help. I think that
you should be clear about what you want and
what you're doing. It's not my job to guess
what you really mean.


> Mar 2, 2011 05:50:04 GMT 10 pts
> [...]
> cd /home
> tar c[...] user
>
> cd /home
> tar x[...]
> [...]

What, exactly, was wrong with that plan? Did
you try it (or anything like it)?

> man basename

echo basename "$HOME"

Just a thought.

You might also consider something like:

cd /home/user
tar c[...] .

cd /home/user
tar x[...]

Perhaps:

cd "$HOME"
or:
cd


In general, "tar" stores paths in the archive
which look like the paths you specify when
you create the archive. Then, when you
extract the files from an archive, it tries
to reproduce those stored paths. If you
don't want to see "/home/user" when you
restore the stuff, then don't say
"/home/user" to "tar" when you create the
archive. Often informative:

tar t[...]

> http://www.gnu.org/software/tar/manual/

Seriously, you _really_ should look at the
documentation. GNU "tar" provides many
options which let you play with the paths
when you create an archive, and when you
extract the files from it. Even if you
insist on creating the archive using
(inappropriate, unhelpful) absolute paths,
GNU "tar" allows you to extract the files to
pretty much any location you might choose.
But wise use of "cd" and appropriate,
relative path specifications can make these
things pretty easy in many cases, even
without using any fancy GNU-"tar"-specific
command options.