LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-09-2019, 03:07 PM   #1
butcho
LQ Newbie
 
Registered: Aug 2019
Location: Florida
Distribution: Ubuntu
Posts: 9

Rep: Reputation: Disabled
Backing up home dir with tar Ubuntu


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.
 
Old 08-09-2019, 03:22 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by butcho View Post
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.

Welcome to LQ
 
Old 08-09-2019, 04:09 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,980

Rep: Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624
Yes, remove the / from date. Pretty sure that will fail.

This may make it easier. https://www.ihaveapc.com/2015/01/bac...nux-using-tar/

Always see if ubuntu pages exist. This however means entire system. https://help.ubuntu.com/community/BackupYourSystem/TAR

I am not sure I'd place any tar in my home however but the examples show.
 
Old 08-09-2019, 04:11 PM   #4
butcho
LQ Newbie
 
Registered: Aug 2019
Location: Florida
Distribution: Ubuntu
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
/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.
 
Old 08-09-2019, 05:45 PM   #5
butcho
LQ Newbie
 
Registered: Aug 2019
Location: Florida
Distribution: Ubuntu
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jefro View Post
Yes, remove the / from date. Pretty sure that will fail.

This may make it easier. https://www.ihaveapc.com/2015/01/bac...nux-using-tar/

Always see if ubuntu pages exist. This however means entire system. https://help.ubuntu.com/community/BackupYourSystem/TAR

I am not sure I'd place any tar in my home however but the examples show.
Jefro you think its a bad idea to use tar on home directory? If thats the case I will continue using Grysnc. Thanks you very much for your input.
 
Old 08-09-2019, 07:34 PM   #6
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,980

Rep: Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624
scasey said what I tried to repeat.

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.

Last edited by jefro; 08-09-2019 at 07:35 PM.
 
1 members found this post helpful.
Old 08-09-2019, 07:40 PM   #7
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
butcho,
You had it in #4. Just do that.
 
Old 08-09-2019, 08:52 PM   #8
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,980

Rep: Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624
Well that was simple.
 
Old 08-10-2019, 06:03 AM   #9
butcho
LQ Newbie
 
Registered: Aug 2019
Location: Florida
Distribution: Ubuntu
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jefro View Post
Well that was simple.
Jefro hello, thank you very much for your help! I did remove / from in front of date. I am planning on running command this way.

cd /
sudo tar -cvzf 2019-08-10-backup.tar.gz /home/butch/

Then after its made I will move to USB drive for safe keeping.
Then if I have to extract or use it. I have command as follows:

cd / move file from USB to root
sudo tar -xvzf 2019-08-10-backup.tar.gz /home/butch/

I am new with this and its a learning experience. I hope I have it right.
 
Old 09-01-2019, 01:22 PM   #10
butcho
LQ Newbie
 
Registered: Aug 2019
Location: Florida
Distribution: Ubuntu
Posts: 9

Original Poster
Rep: Reputation: Disabled
Hello, I have one question?

cd /
sudo tar -cvzf 2019-08-10-backup.tar.gz /home/butch/

Then after its made I will move to USB drive for safe keeping.
Then if I have to extract or use it. I have command as follows:

cd / move file from USB to root
sudo tar -xvzf 2019-08-10-backup.tar.gz /home/butch/

My question is when I go to extract, after doing cd / (root) Do I move file from USB drive to root or do I run extract from USB drive?
 
Old 09-02-2019, 08:43 AM   #11
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
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
 
Old 09-03-2019, 09:15 AM   #12
butcho
LQ Newbie
 
Registered: Aug 2019
Location: Florida
Distribution: Ubuntu
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
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

Thanks in advance
Butch
 
Old 09-03-2019, 09:55 AM   #13
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
lots of problems there

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
 
Old 09-03-2019, 11:11 AM   #14
butcho
LQ Newbie
 
Registered: Aug 2019
Location: Florida
Distribution: Ubuntu
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
lots of problems there

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.
 
Old 09-03-2019, 11:24 AM   #15
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
yeah, the command line can be intimidating.

but once you get the hang of it, it will likely be the first thing you reach for to do something.
 
1 members found this post helpful.
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
copying files from home dir to another dir from another dir in a lower dir chomito44 Linux - General 5 10-19-2013 06:18 PM
tar dir and sub dir removing files but not existing not empty dir j-me Linux - General 2 08-12-2013 11:37 AM
exclude parameter of rsync- 'dir' vs "dir" vs dir rng Linux - General 5 06-13-2012 01:47 AM
Command to display /dir, /dir/sub, /dir/sub/files knockout_artist Linux - Newbie 9 10-25-2007 02:57 PM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:30 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration