LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 02-02-2012, 08:08 AM   #1
Thunderw
LQ Newbie
 
Registered: Apr 2011
Posts: 8

Rep: Reputation: 0
Home backup with tar


Hi,


I would like to backup my server's home directory with tar, which is working fine except the result is a huge file.
Is it possible somehow to make a backup from my users home directories into a e.g: user1.tar.gz, user2.tar.gz etc file instead of home.tar.gz?

Thanks, Thunder
 
Old 02-02-2012, 08:23 AM   #2
Thunderw
LQ Newbie
 
Registered: Apr 2011
Posts: 8

Original Poster
Rep: Reputation: 0
Sorry I forgot to post my current script:

Code:
#!/bin/sh
# ----------------------------------------------------------------------
# ilesystem-snapshot utility: daily snapshots
# ----------------------------------------------------------------------
# should run at 6pm
# ----------------------------------------------------------------------

# ------------- system commands used by this script --------------------
ID=/usr/bin/id;
ECHO=/bin/echo;

RSYNC=/usr/bin/rsync;
TAR=/bin/tar;
RM=/bin/rm;
SU=/bin/su;
SUDO=/usr/bin/sudo;
MD=/bin/mkdir;
MV=/bin/mv;

# ------------- file locations -----------------------------------------

SOURCE4=/etc;
SOURCE5=/home;
SOURCE16=/var;

DESTINATION=/media/synonas/friday;
# ------------- the script itself --------------------------------------

#$SUDO;

# make sure we're running as root
if (( `$ID -u` != 0 )); then { $ECHO "Ohh noes you are not root.  Exiting..."; exit; } fi

# checking backup status

if [ -f $DESTINATION/etc.tar.gz ] ; then \
$RM -r $DESTINATION/etc.tar.gz ;
fi;
if [ -f $DESTINATION/homes.tar.gz ] ; then \
$RM -r $DESTINATION/homes.tar.gz ;
fi;
if [ -f $DESTINATION/var.tar.gz ] ; then \
$RM -r $DESTINATION/var.tar.gz ;
fi;


# Backup file system

$TAR -zcvf $DESTINATION/etc.tar.gz $SOURCE4;
$TAR -zcvf $DESTINATION/homes.tar.gz $SOURCE5;
$TAR -zcvf $DESTINATION/var.tar.gz $SOURCE16;
Attached Files
File Type: txt rsync_fri_test.txt (1.3 KB, 3 views)
 
Old 02-02-2012, 08:51 AM   #3
edgardl
LQ Newbie
 
Registered: Feb 2012
Location: Mexico
Distribution: Debian
Posts: 9

Rep: Reputation: Disabled
Hello

You could use a for loop, I think in something like

Code:
# Backup file system

$TAR -zcvf $DESTINATION/etc.tar.gz $SOURCE4;
$TAR -zcvf $DESTINATION/homes.tar.gz $SOURCE5;
$TAR -zcvf $DESTINATION/var.tar.gz $SOURCE16;

for i in $(ls -l /home); do
 $TAR -zcvf $DESTINATION/$i.tar.gz /home/$i
done
 
Old 02-02-2012, 03:35 PM   #4
jefro
Guru
 
Registered: Mar 2008
Posts: 5,961

Rep: Reputation: 584Reputation: 584Reputation: 584Reputation: 584Reputation: 584Reputation: 584
Maybe not using the best compression?
 
Old 02-02-2012, 07:51 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.2, Centos 5.8
Posts: 11,740

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
Even with max compression, eventually you could end up with huge file if the users store that much data.
Easiest way is to loop through each dir under /home, creating a new backup for each user.
Also means restores are easier for one user.
 
Old 02-03-2012, 07:06 AM   #6
dedec0
Member
 
Registered: May 2007
Posts: 42

Rep: Reputation: 3
For better compression, try piping to 7zip with "ultra" settings

So, now that you have a tar.gz file for each user, you may try other compression mecanisms.

Gzip has not the greatest compressions. Bzip2 is better, and it also has a controlled and small amount of RAM spent to decompress (see man bzip2); I find this interesting for huge files.

Want to try even better compression? But this is not traditional (yet). Try pipeing a tar file to 7z. 7zip gives much better results on many commom cases (for me) and when not, still a little better than the others.

Do not use 7-zip alone to compress the user folders because tar is the right thing for backups. It keeps all file system properties for files.
 
Old 02-04-2012, 06:12 AM   #7
Thunderw
LQ Newbie
 
Registered: Apr 2011
Posts: 8

Original Poster
Rep: Reputation: 0
Hi,

Edgardl,
First of all thanks.

The script works like a charm, now I can throw out my 180GiB tar file
But for some reason it generates weird files eg: dwrxdwrx---.tar.gz all of them are 45byte.

Dedec0,
I will try other compression mechanism too, maybe I could save some space.

Quote:
Originally Posted by edgardl View Post
Hello

You could use a for loop, I think in something like

Code:
# Backup file system

$TAR -zcvf $DESTINATION/etc.tar.gz $SOURCE4;
$TAR -zcvf $DESTINATION/homes.tar.gz $SOURCE5;
$TAR -zcvf $DESTINATION/var.tar.gz $SOURCE16;

for i in $(ls -l /home); do
 $TAR -zcvf $DESTINATION/$i.tar.gz /home/$i
done
 
Old 02-04-2012, 08:58 AM   #8
lithos
Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA, trying desktop Fedora & openSuse
Posts: 852

Rep: Reputation: 133Reputation: 133
Hi

I could maybe suggest you only to try maybe incremental backup to get smaller archive files,
from my incremental TAR backup script.

good luck
 
Old 02-05-2012, 06:32 PM   #9
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.2, Centos 5.8
Posts: 11,740

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
Note also that both gzip & bzip2 have a param to set the amt of compression. Default value is roughly in the middle; better compression equals more time to run & vice-versa.

http://linux.die.net/man/1/gzip
http://linux.die.net/man/1/bzip2
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
tar the last periodic backup that is in another path and move the tar to some dir nelovicov Linux - Newbie 6 01-20-2012 09:40 AM
restoring ONLY the home directory from a complete tar backup irishbitte Linux - Server 5 11-11-2008 08:24 AM
Backup My Home Dir Using Tar? carlosinfl Linux - General 2 03-19-2008 01:30 PM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM
tar as backup imsajjadali Red Hat 4 02-07-2004 03:46 PM


All times are GMT -5. The time now is 01:31 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration