PDA

View Full Version : backup and restore /home/user directory



cccc
March 2nd, 2011, 03:39 PM
Hello

I need a bash scripts to backup and restore /home/user directory include all hidden files.

THX

MadCow108
March 2nd, 2011, 04:01 PM
install grsync (sudo apt-get install grsync) and click all the options you need.
Then Files -> Rsync command line (Alt +R) and you have your simple backup script.

cccc
March 2nd, 2011, 11:23 PM
Thx a lot that's a gerat solution, but what I really need are bash scripts:

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

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

2.) to restore from the backup /save/my_user.tar.gz

cd /home/
tar xvzf my_user.tar.gz; cd -

These scrips should run from a desktop and a normal user should do that.

Shpongle
March 3rd, 2011, 12:34 AM
just put the commands in a bash file

use $HOME for the home directory as its dynamic.

put this in a file called backup.sh , for example

#! /bin/bash

echo 'Backing up home dir'
tar cvzf /save/backup.tar.gz $HOME

make it executable by chmod u+x backup.sh

run it by /path/to/script/backup.sh


now do the same for the other one

see here for more details http://www.freeos.com/guides/lsst/ch02sec01.html

eerror
March 3rd, 2011, 12:43 AM
Personally I like rsync for backups (rather than tar and gz).
That way only files that changed get copied over.

rsync -avt /srcdir /destdir

The first time you run it it will copy everything.
If you run it 2nd time right away it will not copy anything.
Now change a file in your home directory and run the command again.
Only that changed file will copy over.

cccc
March 3rd, 2011, 01:13 AM
I've created these scripte using $HOME parameter:

#! /bin/bash
echo 'Backing up user home dir'
cd /home
tar cvzf /home/user/save/backup.tar.gz $HOME

and now restore:

#! /bin/bash
echo 'Restore user default settings'
cd /home
tar xvzf /home/user/save/backup.tar.gz

then I get /home/user/home/user directory created instead of extracting directly into /home/user/*

Both scripts should by run by a normal user.

cyberslayer
March 3rd, 2011, 06:14 AM
...

Try "man tar" to see the documentation for tar. Why do you think it is creating the extra directory?

cccc
March 3rd, 2011, 01:04 PM
Try "man tar" to see the documentation for tar. Why do you think it is creating the extra directory?

If I run tar xvzf /home/user/save/backup.tar.gz I can see, the extra /home/user/home/user will be created, instead of extracting directly into /home/user/*.
That's not what I want.

cccc
March 4th, 2011, 02:13 AM
I still cannot find a solution.

Some Penguin
March 4th, 2011, 04:04 AM
You still aren't reading documentation and thinking things through instead of going to a forum with "I want, I want, I want".

cccc
March 6th, 2011, 02:21 AM
I solved this problem using these scripts:

#! /bin/bash
echo 'Backing up user home dir'
cd /home
tar cvzf /usr/backup/user_backup.tar.gz .with a dot at the end

and now restore:

#! /bin/bash
echo 'Restore user default settings'
cd /home
tar xvzf /usr/backup/user_backup.tar.gz