Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
how do I create a compressed tar archive with gzip
-
- Posts: 36
- Joined: 2018-05-09 10:56
- Location: United KIngdom
how do I create a compressed tar archive with gzip
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
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
-
- Posts: 1405
- Joined: 2009-09-10 20:15
- Location: Saint-Petersburg, Russian Federation
- Been thanked: 11 times
Re: how do I create a compressed tar archive with gzip
scp transmits files only, not directories.
And what Net is need for tar? "man tar" is quite enough.
Peter.
And what Net is need for tar? "man tar" is quite enough.
Code: Select all
tar zcvf name.tar.gz directory
Last edited by peter_irich on 2018-05-26 19:26, edited 1 time in total.
-
- Global Moderator
- Posts: 3049
- Joined: 2017-09-17 07:12
- Has thanked: 5 times
- Been thanked: 132 times
Re: how do I create a compressed tar archive with gzip
gzip does not create an archive (a structured container for files and directory). It just compresses a single file or a stream.jaytelford wrote:Create a compressed tar archive using gzip
tar creates a tar archive, and optionnally uses gzip to compress it.
What about the -r option ?peter_irich wrote:scp transmits files only, not directories.
Code: Select all
-r Recursively copy entire directories. Note that scp follows sym‐
bolic links encountered in the tree traversal.
-
- Posts: 1405
- Joined: 2009-09-10 20:15
- Location: Saint-Petersburg, Russian Federation
- Been thanked: 11 times
Re: how do I create a compressed tar archive with gzip
What about the -r option ?peter_irich wrote:scp transmits files only, not directories.
Code: Select all
-r Recursively copy entire directories. Note that scp follows sym‐
bolic links encountered in the tree traversal.
Peter.
Last edited by peter_irich on 2018-05-26 19:24, edited 1 time in total.
-
- Posts: 36
- Joined: 2018-05-09 10:56
- Location: United KIngdom
Re: how do I create a compressed tar archive with gzip
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 stepsgzip does not create an archive (a structured container for files and directory).
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
Re: how do I create a compressed tar archive with gzip
First two tasks can be done in one command: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.
Code: Select all
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
-
- df -h | grep > 20TiB
- Posts: 1418
- Joined: 2012-10-06 05:31
- Location: /dev/chair
- Has thanked: 79 times
- Been thanked: 189 times
Re: how do I create a compressed tar archive with gzip
The Unix way is with pipes, e.g.: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.
Code: Select all
$ tar zcf - [somefiles] | ssh user@destination 'cat - > archive.tar.gz'
Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.
- stevepusser
- Posts: 12930
- Joined: 2009-10-06 05:53
- Has thanked: 41 times
- Been thanked: 71 times