how do I create a compressed tar archive with gzip

If none of the more specific forums is the right place to ask

how do I create a compressed tar archive with gzip

Postby jaytelford » 2018-05-26 02:37

Hi,

I need to create a backup of two directories on my server.

I have searched around for ways to do this using gzip to create a compressed tar archive and then scp it through an ssh tunnel, to my local machine from my remote server. I am a bit confused though because the sites I have found on Google don't really explain it properly or give examples - they just blast off a load of flags and then other people or other sites contradict each other; telling you to use different flags or to use the pipe, where others say not to.

Can somebody please explain to me how I can do this:

1: Create a compressed tar archive using gzip of my httpdocs directory
2: Connect to my local machine from my remote server using ssh
3: scp the compressed tar archive created in step 1 to my local machine from my remote server through an ssh tunnel

I know how to use ssh and I know how to scp files/directories via terminal but I don't really understand how to create the compressed tar archive and I don't really understand how to put all the steps together into a terminal command.

Thanks
Jay

NB
Just to be clear, I want to use these archives as backups and store them on my local machine
jaytelford
 
Posts: 8
Joined: 2018-05-09 10:56
Location: United KIngdom

Re: how do I create a compressed tar archive with gzip

Postby Bulkley » 2018-05-26 03:13

There are on the Net so many instructions for the various tar operations that I can't be bothered remembering any of it. It will be an easy search.
Bulkley
 
Posts: 5569
Joined: 2006-02-11 18:35

Re: how do I create a compressed tar archive with gzip

Postby peter_irich » 2018-05-26 08:02

scp transmits files only, not directories.
And what Net is need for tar? "man tar" is quite enough.
Code: Select all
tar zcvf name.tar.gz directory


Peter.
Last edited by peter_irich on 2018-05-26 19:26, edited 1 time in total.
peter_irich
 
Posts: 1227
Joined: 2009-09-10 20:15
Location: Saint-Petersburg, Russian Federation

Re: how do I create a compressed tar archive with gzip

Postby p.H » 2018-05-26 08:30

jaytelford wrote:Create a compressed tar archive using gzip

gzip does not create an archive (a structured container for files and directory). It just compresses a single file or a stream.
tar creates a tar archive, and optionnally uses gzip to compress it.

peter_irich wrote:scp transmits files only, not directories.

What about the -r option ?
Code: Select all
     -r      Recursively copy entire directories.  Note that scp follows sym‐
             bolic links encountered in the tree traversal.
p.H
 
Posts: 394
Joined: 2017-09-17 07:12

Re: how do I create a compressed tar archive with gzip

Postby peter_irich » 2018-05-26 13:34

peter_irich wrote:scp transmits files only, not directories.

What about the -r option ?
Code: Select all
     -r      Recursively copy entire directories.  Note that scp follows sym‐
             bolic links encountered in the tree traversal.

Excuse me, I forgot this option. I prefer to send compressed directories.

Peter.
Last edited by peter_irich on 2018-05-26 19:24, edited 1 time in total.
peter_irich
 
Posts: 1227
Joined: 2009-09-10 20:15
Location: Saint-Petersburg, Russian Federation

Re: how do I create a compressed tar archive with gzip

Postby jaytelford » 2018-05-26 14:49

gzip does not create an archive (a structured container for files and directory).


I had realised this and indeed that is what I was referring to. I wanted to create the tar archive and then compress it using gzip. After than I wanted to transfer it to my local machine. I kind of understood how to do this with multiple steps

create the tar archive
compress it using gzip
transfer it from remote to local
rm -rf the compressed archive from the remote

What I had actually wanted to do however - was create the tar archive, compress it with gzip and transfer it to my local machine in a single step, without needing to go back and then rm -rf it from the remote.

So basically I wanted to transfer a compressed tar archive of the directories that I need to backup to my local machine, without having to physically create the archive on the remote and then having to go back and delete it.

Sorry, it seems I wasn't clear enough in my initial question but I was tired at the time I wrote it, so what made sense to my sleepy brain probably didn't make sense to anyone else's.

Cheers
Jay
jaytelford
 
Posts: 8
Joined: 2018-05-09 10:56
Location: United KIngdom

Re: how do I create a compressed tar archive with gzip

Postby arzgi » 2018-05-26 16:14

jaytelford wrote:I I kind of understood how to do this with multiple steps

create the tar archive
compress it using gzip
transfer it from remote to local
rm -rf the compressed archive from the remote

What I had actually wanted to do however - was create the tar archive, compress it with gzip and transfer it to my local machine in a single step, without needing to go back and then rm -rf it from the remote.

First two tasks can be done in one command:
Code: Select all
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file


You can write a bash script, one command on each line. To make sure it works, test each command separately. Then make script executable (chdmod u+x [script]). After that you only have run that script.
arzgi
 
Posts: 134
Joined: 2008-02-21 17:03
Location: Finland

Re: how do I create a compressed tar archive with gzip

Postby steve_v » 2018-05-29 07:57

jaytelford wrote:I wanted to transfer a compressed tar archive of the directories that I need to backup to my local machine, without having to physically create the archive on the remote and then having to go back and delete it.
The Unix way is with pipes, e.g.:
Code: Select all
$ tar zcf - [somefiles] | ssh user@destination 'cat - > archive.tar.gz'

Tars STDOUT is passed over SSH to cat on the receiving end, which writes it to a file. More.
steve_v
 
Posts: 695
Joined: 2012-10-06 05:31
Location: New Zealand

Re: how do I create a compressed tar archive with gzip

Postby stevepusser » 2018-05-29 16:29

Obligatory xkcd reference:

Image
The MX Linux repositories: Backports galore! If we don't have something, just ask and we'll try--we like challenges. New packages: GIMP 2.10.2, Pale Moon 27.9.3, wine-staging 3.10, QuiteRSS 0.18.11, Linux kernel 4.17, Krita 4.0.4
User avatar
stevepusser
 
Posts: 9631
Joined: 2009-10-06 05:53


Return to General Questions

Who is online

Users browsing this forum: No registered users and 4 guests

fashionable
cron