Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
This is command that I run in tar. My question is should exclude the fill so it not kept in the backup?
sudo tar -cvzf /2019-08-07-backup.tar.gz /home/butch/
In other words should I add after backup file and before /home/butch --exclude /2019-08-07-backup.tar.gz
I have read some says do it and some say not. I would just like to know the right way.
This is command that I run in tar. My question is should exclude the fill so it not kept in the backup?
sudo tar -cvzf /2019-08-07-backup.tar.gz /home/butch/
In other words should I add after backup file and before /home/butch --exclude /2019-08-07-backup.tar.gz
I have read some says do it and some say not. I would just like to know the right way.
/2019... is not in /home/butch. It’s a file in the root directory, so it doesn’t need to be excluded,
That, by the way, is the correct usage. You shouldn’t have the tarfile inside the directory being backed up.
/2019... is not in /home/butch. It’s a file in the root directory, so it doesn’t need to be excluded,
That, by the way, is the correct usage. You shouldn’t have the tarfile inside the directory being backed up.
Welcome to LQ
Ok thanks so much for your answer. I will use this command to back home directory. sudo tar -cvzf /2019-08-07-backup.tar.gz /home/butch/ then after I run it I will move the file to my usb drive for keeping. Hopefully never needing! Again Thanks alot.
Did you get the part about your file name with a / in front?
He also said this.
"You shouldn’t have the tarfile inside the directory being backed up"
I'd tend to agree that a tar or backup inside the subdirectory you are backing up could cause an issue. So I simply never do it.
tar is a very well tested program and has been used for decades and decades. It is the go to tool for millions. However there may be other tools that can do just as good of a job.
I think I started answering it in last thread then got distracted.
you don't need to move it off the usb
keep in mind that "tar xf" by default will spit everything out into the PWD ( present working directory )
( you can change it with options, see "man tar" )
so
Code:
cd /
pwd # make sure we are in the right place
tar tf /path/to/usb/mountpoint/path/to/2019-08-10-backup.tar.gz
# good to check what is in the tar before spilling it out where it should not be
#
tar xf /path/to/usb/mountpoint/path/to/2019-08-10-backup.tar.gz
Now, Personally I wouldn't have created the tar in the same way
Code:
cd # assuming you are backing up your own home
pwd # make sure we are where we want to be
tar cfJ /path/to/usb/mountpoint/path/to/2019-08-10-backup.tar.gz ./
# but nothing "wrong" with
tar cfJ /path/to/usb/mountpoint/path/to/2019-08-10-backup.tar.gz /home/butch
it is just personal preference
It really depends on what I'm taring up
if I'm taring up some project, I will always tar the dir
Code:
tar cf /path/to/project-v12.08.9.tar.xz project-v12.08.9/
so when untared we get a nice dir and no junk at our feet.
and if I'm backing up /usr/local
something like
Code:
tar cfJ /path/to/2019-09-02-_usr_local.tar.xz /usr/local
basically I replace / with _ and it tells me at a glance what is in it and how the path is stored
( still do "tar tf" to double check )
there are options to strip leading paths, I only remember there are option not what they are
I think I started answering it in last thread then got distracted.
you don't need to move it off the usb
keep in mind that "tar xf" by default will spit everything out into the PWD ( present working directory )
( you can change it with options, see "man tar" )
so
Code:
cd /
pwd # make sure we are in the right place
tar tf /path/to/usb/mountpoint/path/to/2019-08-10-backup.tar.gz
# good to check what is in the tar before spilling it out where it should not be
#
tar xf /path/to/usb/mountpoint/path/to/2019-08-10-backup.tar.gz
Now, Personally I wouldn't have created the tar in the same way
Code:
cd # assuming you are backing up your own home
pwd # make sure we are where we want to be
tar cfJ /path/to/usb/mountpoint/path/to/2019-08-10-backup.tar.gz ./
# but nothing "wrong" with
tar cfJ /path/to/usb/mountpoint/path/to/2019-08-10-backup.tar.gz /home/butch
it is just personal preference
It really depends on what I'm taring up
if I'm taring up some project, I will always tar the dir
Code:
tar cf /path/to/project-v12.08.9.tar.xz project-v12.08.9/
so when untared we get a nice dir and no junk at our feet.
and if I'm backing up /usr/local
something like
Code:
tar cfJ /path/to/2019-09-02-_usr_local.tar.xz /usr/local
basically I replace / with _ and it tells me at a glance what is in it and how the path is stored
( still do "tar tf" to double check )
there are options to strip leading paths, I only remember there are option not what they are
man tar
^^^ long read
Hello I have tried to make tar backup and restore from what I have come up with reading. Can you tell me if this would work? I am backing up to usb then restoring from usb to home directory.
Backing up Home Directory with Tar
cd /
pwd #
sudo tar -cvzf media/butch/USB DISK 2019-09-04-backup.tar.gz /home/butch/
Then if I have to extract or use it. I have command as follows.
I will want to restore from a Live CD.
cd /
pwd #
sudo tar -xvzf 2019-08-10-backup.tar.gz /home/butch/ media/butch/USB DISK
the first is that you have spaces in the file path (USB<space>DISK)
you need wrap those with ""
also please use
[code] <--- before
Code:
tar -cvzf "media/butch/USB DISK/2019-09-04-backup.tar.gz" /home/butch/
# I added ^ ^ ^
[/code] <-- after
^^^ makes things more readable
you don't need the use sudo
now, that works because you are in the root dir /
Code:
tar -cvzf "/media/butch/USB DISK/2019-09-04-backup.tar.gz" /home/butch/
# see ----^
now that you have full paths you do not need to
Code:
cd /
another way is to have USB\ DISK
which is automagic if you use tab completion
<tab> is your tab key,
Code:
tar -cvzf /me<tab>bu<tab>U<tab>2019-09-04-backup.tar.gz ~/
~/ is short your home dir
[/code]
to restore
Code:
tar -C / -xf "/media/butch/USB DISK/2019-09-04-backup.tar.gz"
try you new tab completion trick
from man tar
Code:
-C, --directory=DIR
Change to DIR before performing any operations. This option is order-sensitive, i.e. it affects all
options that follow.
you need that as you archived with fullpath home/butch
you could just change to root dir first, but that is for people who haven't read the manpage
I would like to thank you for your help! I think tar is way ahead of me. I am currently using Grysnc and it works ok for me. I thought I might be able to use tar with command line but its to many problems for me being a new user. Again thank you very much for your help.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.