LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need help with a tar command (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-with-a-tar-command-830220/)

taylorkh 09-03-2010 05:40 PM

Need help with a tar command
 
Ubuntu 10.04

As part of my nightly backup script I archive my home directory with the following command
Quote:

tar -cvpzf /quitelarge/_mirror/mirror1/home-ken.gz /home/ken 2>> /quitelarge/_mirror/tar-error.log
It seems to work fine and I have recovered files from the archive on occasion. Actually I keep 7 rolling daily backups and a monthly burn to DVD. That said, yesterday I had an issue...

I had an sftp connection made by Nautilus to my server. Ubuntu for whatever reason places an icon on the desktop showing the connection. When I ran the script it decided to archive everything on my server - all 1.4 TB. I caught the problem when home-ken.gz was about 5 GB. I stopped the process, closed the sftp connection, rolled back the backups and tried again. This time I got a file of the expected size - about 45 MB.

In the error log I did find that the tar process was trying to suck the entire contents of the server into the archive file
Quote:

tar: /home/ken/.gvfs/sftp for ken on taylor10/proc/asound/ICH5/pcm0c/sub0: file changed as we read it
tar: /home/ken/.gvfs/sftp for ken on taylor10/proc/asound/ICH5/pcm0c: file changed as we read it
tar: /home/ken/.gvfs/sftp for ken on taylor10/proc/asound/ICH5: file changed as we read it
tar: /home/ken/.gvfs/sftp for ken on taylor10/proc/asound: file changed as we read it
tar: /home/ken/.gvfs/sftp for ken on taylor10/proc/scsi: file changed as we read it
tar: /home/ken/.gvfs/sftp for ken on taylor10/proc/acpi/event: Cannot open: Permission denied
tar: /home/ken/.gvfs/sftp for ken on taylor10/proc/acpi/fadt: Cannot open: Permission denied
tar: /home/ken/.gvfs/sftp for ken on taylor10/proc/acpi/dsdt: Cannot open: Permission denied
tar: /home/ken/.gvfs/sftp for ken on taylor10/proc/irq/21/smp_affinity: Cannot open: Permission denied
So the question is... is there an option I can place on the tar command to tell it NOT to follow the ssh connection which is sitting on my desktop? The closest thing I see in the documentation is -h which tells tar to "follow symlinks; archive and dump the files they point to." I am NOT specifying -h so if the ssh connection is treated as a symlink by tar I would still not expect the remote contents to be tarred.

TIA,

Ken

unSpawn 09-03-2010 07:20 PM

See 'man tar', the "--exclude" and "--exclude-from" switches?

taylorkh 09-03-2010 08:31 PM

OK -exclude but what to exclude? The properties for the icon on the desktop are as follows
Quote:

Name: sftp for ken on taylor10
Type: folder(inode/directory
Contents: 20 items, totalling 2.9 MB
Location: on the desktop
Volume: sftp for ken on taylor10
If I click on the icon I see the contents of my home folder on taylor10, the server, (7 folders and one link to folder) or if I show hidden file there are of course a lot of them. So I have no idea what the 20 items refers to.

Further confusing me is the fact that if I issue ls -a when my terminal pwd is the Desktop I see nothing as far as the sftp icon.

What pattern do I try to exclude???

Ken

unSpawn 09-04-2010 05:23 AM

Try something like '--exclude /home/ken/.gvfs/sftp\ for\ ken\ on\ taylor10/'?

jmc1987 09-04-2010 06:14 AM

I use tar like this

say I was backing up my system.
Code:

tar -cvpzf /path/to/backup.tgz --exclude=/dev --exclude=/mnt --exclude=/media --exclude=/sys --exclude=/proc --exclude=lost+found /
Just replace /path/to/backup.tgz, any --exclude=yourFiles, and / with your info.

Just to add you may want to do your script like this.
Code:

tar -cvpzf /quitelarge/_mirror/mirror1/home-ken.tgz --exclude=/home/ken/.gvfs/sftp\ for\ ken\ on\ taylor10/proc /home/ken
Somebody feel free to correct me if Im wrong but I think that will resolve your issue

MTK358 09-04-2010 06:54 AM

Quote:

Originally Posted by taylorkh (Post 4087509)
OK -exclude but what to exclude? The properties for the icon on the desktop are as follows
If I click on the icon I see the contents of my home folder on taylor10, the server, (7 folders and one link to folder) or if I show hidden file there are of course a lot of them. So I have no idea what the 20 items refers to.

Further confusing me is the fact that if I issue ls -a when my terminal pwd is the Desktop I see nothing as far as the sftp icon.

It's a Desktop File. It contains the name of what it refers to and it's treated specially by GUI file managers, but not the command line. Post the output of ls in the desktop directory when the icon is showing.

taylorkh 09-04-2010 08:05 AM

Thanks folks! I think I am on the track of a solution. There is nothing on my Desktop related to this issue
Quote:

ken@taylor12:~/Desktop$ ls -la
total 15928
drwxr-xr-x 2 ken ken 4096 2010-09-04 08:47 .
drwxr-xr-x 60 ken ken 4096 2010-09-04 08:49 ..
-rw-r--r-- 1 ken ken 2185470 2010-07-13 16:39 catalogCMP2010.pdf
-rw-r--r-- 1 ken ken 2713874 2006-02-06 17:39 Guidelines to GTAW.pdf
-rw-r--r-- 1 ken ken 99 2010-08-21 08:35 Matt
-rw-r--r-- 1 ken ken 11369609 2006-08-11 11:36 TIG Handbook.pdf
ken@taylor12:~/Desktop$
However, if I backup to /home/ken I find a hidden folder .gvfs whih contains
Quote:

ken@taylor12:~/.gvfs$ ls -la
total 8
dr-x------ 3 ken ken 0 2010-09-03 12:32 .
drwxr-xr-x 60 ken ken 4096 2010-09-04 08:49 ..
drwx------ 1 ken ken 4096 2010-06-05 07:34 sftp for ken on taylor13wl
taylor13wl is my netbook to which I am currently connected.

To make the solution generic I believe I want to -exclude /home/ken/.gvfs That should fix the problem regardless of which computer(s) I might be connected to during the backup. I will give it a try.

Ken

taylorkh 09-04-2010 08:41 AM

Well I though I was on to something :( Here is my test command
Quote:

ken@taylor12:~$ tar -cvpzf --exclude=/home/ken/.gvfs /quitelarge/home-ken.gz /home/ken 2>> /quitelarge/tar-error.log
which results in the following errors
Quote:

tar: Removing leading `/' from member names
tar: /quitelarge/home-ken.gz: Cannot stattar: --exclude=/home/ken/.gvfs: Cannot open: No such file or directory
: No such file or directory
tar: Error is not recoverable: exiting now
I tried placing the path I wished to exclude (/home/ken/.gvfs) in a file (/quitelarge/excudethiscrap) and issued this command
Quote:

ken@taylor12:~$ tar -cvpzf --exclude=/quitelarge/excludethiscrap /quitelarge/home-ken.gz /home/ken 2>> /quitelarge/tar-error.log
which resulted in
Quote:

tar: Removing leading `/' from member names
tar: /quitelarge/home-ken.gz: Cannot stattar: --exclude=/quitelarge/excludethiscrap: Cannot open: No such file or directory
: No such file or directory
tar: Error is not recoverable: exiting now
removing the = sign allowed the process to run although it tried to archive the entire remote computer.

Ken

unSpawn 09-04-2010 09:00 AM

'tar -${args}f /path/to/ball.tar --exclude /path/to/file --exclude /path/to/dir /path/to/tarsource' works for me OK.

taylorkh 09-04-2010 11:43 AM

Perhaps it is because .gvfs is a hidden subdirectory???

Ken

jmc1987 09-04-2010 02:48 PM

Code:


sudo tar -cvpzf /quitelarge/home-ken.tgz  --exclude=/home/ken/.gvfs  /home/ken 2>> /quitelarge/tar-error.log

I rewrote your code so this one should work for you

try this assuming you have a folder quitelarge in your / direcotry.

taylorkh 09-04-2010 03:18 PM

Thanks jmc1987, that worked (without the sudo - I own everything in my home directory tree). I have looked at several man pages for tar. None of them seem to describe any specific order or precedence for options, operators, operands etc. At least this information did not jump out at me.

I have incorporated the syntax you provided in my script.

Thanks again,

Ken

p.s. /quitelarge is /dev/sdb1 - my 750 GB drive and /veryhuge is /dev/sdc1 my 1 TB drive. /, /home, /data and swap are on my 10k RPM Velociraptor 150 GB drive. And despite an i7-860 quad processor and 8 GB of RAM my Atom processor netbook boots Ubuntu 9.04 faster than this pig of a desktop boots 10.04. Oh well.

jmc1987 09-04-2010 04:00 PM

Hmm no sudo. I guess you own that folder quitelarge ;)

Glad to see if it works. But the credit belongs mostly to linuxquestions.org. They've help me most with that pesky tar command.

just to add you didn't need that part of the command "2>> /quitelarge/tar-error.log". I put it there just it case you wanted your errors logged.
Good luck to you.

taylorkh 09-04-2010 06:45 PM

I have found the error logging to be helpful. In fact when I first developed the script it showed me a couple of files in my home tree which I did not own. Don't remember what the were but I own them now!

I paid for /quitelarge so I guess I should own it :D The machine is a Dell XPS 8000. It came with the 750 GB drive and Windoze 7 (after a month of waiting and raising H with Dell.) I had the Velociraptor waiting - had purchased it on sale from newegg. I had been looking for an external hard drive docking gizmo (insert the drive and plug the cable into USB.) Around New Years day newegg had the dock and a WD Black Caviar 1 TB drive for something like $79. Normal price of the dock was about $35 - what a deal. So now the machine is full of storage - well actually over full. One of the drives is in a floppy drive bay.

The machine is quite powerful. The only real problems I have with it are suspend (which does suspend but often does not wake up correctly - I find I am logged out) and printing some pdf files such as my statement from Citicards. The only way I can print it is to use the "genuine" Acrobat reader in a Win 7 virtual machine running under VMWare. No Linux pdf reader nor Foxit on XP will print the dang thing. Same with some pdfs I created with Xsane using my scanner. Created them in Linux, can view them in Linux but not print.

Ken


All times are GMT -5. The time now is 12:00 AM.