Solved

need to backup system to a directory on my system

Posted on 2004-08-26
12
217 Views
Last Modified: 2010-04-20
Hello.

I need to backup my whole system to a directory on my system.

I have root access to my remotely located dedicated server.  I have 2 gigs of stuff on there and I connect to the Internet with a modem, so there is not way I can download a backup.  So my only option it to backup my system on my system-- better than nothing.

How can I do this?  Can I create a tar.gz file of everything  in /backup/ ?

Thanks!
0
Comment
Question by:hankknight
  • 5
  • 2
  • 2
  • +3
12 Comments
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 11906130
yeh
 
tar -cf backup.tar /backup

then gzip -d9 backup.tar

that should work
0
 
LVL 11

Expert Comment

by:avizit
ID: 11906180
you can do it in one command

tar -cvzf bkp.tar.gz /backup

or zip with bzip2

tar -cvjf bkp.tar.bz2 /backup
0
 
LVL 16

Author Comment

by:hankknight
ID: 11906721
Will

    tar -cvzf bkp.tar.gz /backup

preserve all permissoins and ownership correctly?
0
 
LVL 16

Author Comment

by:hankknight
ID: 11906746
By the way, it looks like your suggestions will just backup the contents of /backup/

I want to backup EVERYTHING and place a tar.gz of the backup of everything in /backup/
0
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 11906938
try doing:
 
tar -cf backup.tar  /

then gzip -d9 backup.tar

then cp backup.tar.gz /boot
0
 
LVL 17

Expert Comment

by:owensleftfoot
ID: 11907753
zip -R /mydir/backup /*
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 16

Author Comment

by:hankknight
ID: 11908549
Is there a one-step process for a gzip tar that will preserve permissions and ownership?
0
 
LVL 11

Expert Comment

by:avizit
ID: 11909462
while tarring  you may like to exclude the /backup directory

i mena you really dont want to take a backup of the backup directory ..
you will run out of space very soon

gnu tar has -exclude option to exclude a directiry

for permission

from tar manpage ( GNU)

 -p, --same-permissions, --preserve-permissions
              extract all protection information
 --same-owner
              create extracted files with the same ownership
0
 
LVL 3

Expert Comment

by:gnudiff
ID: 11912027
1. tar/gzip will do fine.
tar --exclude /backup -czf /backup/files-0`date +%w`.tgz  /
this command will give you full backups for every weekday, if you need that.

2. I recommend at least backing up to a different partition (if possible, on a different harddrive) that is mounted just for the time of backup. While not a magic bullet, it might help a bit in case of a crash.

3. In my experience, if the system goes down, one may usually want to reinstall/install a newer version anyway. In that case there is only a handful of system directories you really want to save, not the whole installed application suite.

Here is a tcsh shell script for archiving I use myself:
-----------------------
#!/bin/tcsh
cd /
set EXEDIR=/root/bin  # where the backup script and associated files reside;
set BKDIR=/var/backup # backup directory -- a separate partition mounted for backup time only
set DT=`/bin/date +%w` # variable part of backup filename, currently weekday number
set FS_BKFILE="fsys-${DT}.tgz"  # full filename of backup file
set INCFILES=$EXEDIR/incfiles.bk  # list of directories/files to backup
set EXCFILES=$EXEDIR/excfiles.bk  # list of dirs/files NOT to backup, this will be a subset of $INCFILES
mount $BKDIR
# status 0 - mount OK, status 32 - already mounted
if ($status == 0 || $status == 32) then
        tar -czf $BKDIR/$FS_BKFILE --files-from=$INCFILES -X $EXCFILES
        if ($status != 0) then
                echo "Error in fs backup!"
        endif
        umount $BKDIR
else
        echo "Couldn't mount $BKDIR for archiving!"
endif
--------------
Also you need 2 files incfiles.bk that say which directories you will backup,
and excfiles.bk, which says which directories OF incfiles.bk you will NOT backup.
On my system these are like:
--- infciles.bk----
etc/
root/
var/named/
var/spool/cron/crontabs/
data/sql/*.conf
home/
data/web/
usr/local/roxen/configurations/
----
this will backup most system config dirs, user home dirs and web server root; adapt as needed.
/var/named is where DNS server configuration is commonly stored


--- excfiles.bk ---
data/web/admin/stats
*~
----
this will make backup exclude all backup files (*~) as well as a web directory that holds data, which is regenerated every night anyway.

0
 
LVL 16

Author Comment

by:hankknight
ID: 11912201
Will this backup everything except the /backup/ directory and everything in it?

And will copy ALL files (including system files and hidden files) and preserve all ownership and permissions?

    tar -czpsf /backup/aug27.tgz mystuff/ --compress --same-owner --exclude-from /backup/

Thanks!
0
 
LVL 16

Author Comment

by:hankknight
ID: 11912214
The above had a typo.  I meant this:

tar -czpsf /backup/aug27.tgz --compress --same-owner --exclude-from /backup/
0
 
LVL 2

Accepted Solution

by:
stanford_16 earned 500 total points
ID: 11914399
hankknight,

To answer your latest question:  Yes, the command you typed:

#tar -czpsf /backup/aug27.tgz --compress --same-owner --exclude-from /backup/

Will do what you want it to do.  However, I have a suggestion for a more robust solution.  rdiff-backup is a program designed for mirroring one directory to another.  It fulfills both your initial requirement (backing up the system to a directory while preserving subdirectories, hard links, dev files, permissions, uid/gid ownership, and modification times) as well as two others you may not have considered:

1.  It uses reverse diffs, which allow you to recover deleted files and restore system configurations.

2.  It can be easily modified to transfer the data over a network when you wish to do so.

Here's the link:
http://rdiff-backup.stanford.edu/

Good luck!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
add a 1000 ms delay after each sending email operation 12 68
Changing passwords in Linux Systems 3 39
mcrypt_create_iv() is deprecated 4 67
how to rebuild XFS volume from LV 19 28
I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now