bahattab
31-08-2008, 11:37 AM
Compress folder Test/ to Test.tar.gz
tar czfv Test.tar.gz Test/
czfv = ‘Compress Zip File Verbose’
If you want bzip files, use ‘j’ instead of ‘z’.
Uncompress Test.tar.gz to folder Test/
tar -xzvf Test.tar.gz
x = ‘eXtract’
Again, if you want bzip files, use ‘j’ instead of ‘z’.
Archive Contents (http://txt.binnyva.com/2008/07/archive-contents/)
Show contents of an archive
tar -tf archive.tar
http://txt.binnyva.com/2007/02/command-to-compressuncompress-targz-and-tarbz2-files/
if you want to make a file with a 2GB maximum you wauld hove:
tar czvf -L 2 allmyfiles.tar.gz myfile
http://www.linuxforums.org/forum/linux-newbie/29236-making-tar-gz-file-linux.html
To put everything in the D folder into a tar file in the backup folder.
For .tar.gz:
sudo tar -czf /home/backup/D_backup$(date +"%Y%m%d").tar.gz /home/D
For .tar.bz2 (higher compression, takes longer):
sudo tar -cjf /home/backup/D_backup$(date +"%Y%m%d").tar.bz2 /home/D
You might want to read up on gpg for the encryption.
http://ubuntuforums.org/showthread.php?t=573290
Backup and split archive with tar
If you want to use tar, try something like this:
tar -cvlf - / | split -a 2 -b 2000m - /mnt/big_backup.tar
You must specify the -l switch for tar, so it stays within one filesystem. Otherwise it'll try to backup the backup file that split just created! This also means you'll have to create a separate backup for each partition that you have.
Now, you have several files /mnt/big_backup.tarxx,
how can you extract them ? http://www.atyafonline.com/vb/imgcache/891.png
tried this:
tar -cv --exclude "/mnt" -f - / | split -a 2 -b 2000m - /mnt/big_backup.tar
or
cat big_backup.tar* | tar -tvf - ought to do it.
http://forums.bsdnexus.com/viewtopic.php?id=403
Tar.gz - A Quick and Easy Compression and Extraction Command Line
Sun, 2007-05-13 00:36 — keith
http://www.atyafonline.com/vb/imgcache/886.png
What I am going to do next is to introduce a very simple, quick and easy way of compression (zipping) and decompression (extracting) files using command line. This may be relatively easy to many users, especially to Linux experts. However, not everyone is an expert in that sense.
Learning to use command line to archive files can be a very beneficial. First of all, it does not use Graphical User Interface (GUI), therefore there is more resources made available for your systems (instead of using them on GUIs). Secondly, you are able to access remote systems using Secure Shell (SSH) connections and perform tasks on the remote systems, as though they are directly on your systems; that is, for example accessing web hosting servers via SSH to backup your web sites (although I know backup functions do exist in cPanel). Well, the list may still continue, but I shall stop here.
(learn more by clicking here... (http://www.neohide.com/tar-gz-a-quick-and-easy-compression-and-extraction-command-line))
Creating An Archive
Assume you are on a text console, and you would like to zip up a folder at your current directory say "abcfolder", simply run the following command:
tar czvf myfolder.tar.gz abcfolder/
The above command creates an archive file name, myfolder.tar.gz. Everything under the directory abcfolder/ will be compressed and stored.
To compress all the files within a folder:
tar czvf allmyfiles.tar.gz *
The above command thus compresses all the files (including subfolders) within the directory and archived it as allmyfiles.tar.gz.
Basically, there are various variants you can play around with tar command in Linux. All you need is to type "man tar" to find out more information. So next, let's extract these files.
Extracting Files from Archive
Extracting is probably quite easy. If you have a .tar.gz file, simply type the command to extract all the files and folders to the current folder you are in.
tar -xzvf extractme.tar.gz
The above command extracts the archive, extractme.tar.gz to your current folder or directory.
So, you see, it's not really that difficult to use compress and uncompress files and folders in linux via command line. It's time to throw away some of GUIs.
http://www.neohide.com/tar-gz-a-quick-and-easy-compression-and-extraction-command-line
Compressing the Package
Create /downloadFolderinside /YourMainFolder
At this point, you have either used FTP to send the file to your web space, or used File Manager. The tar.gz file should now be in http://yourdomain/YourMainFolder/downloadFolder.
We will need to decompress the tar.gz package in order to use the software. To decompress the file, we will need to create either a PHP script (preferred) or Perl script.
To create the PHP script, you will need to create a New File with File Manager (or upload the completed text file with FTP). To create a New File in File Manager:
Log in to the CPanel (https://login.yourdomain.com/), then click "File Manager." (...if you are not already logged in to File Manager.)
If you are not yet in the YourDomain/YourMainFolder/downloadFolder folder, select the YourMainFolder link, and then the downloadFolder link on the following page.
You will now see the .tar.gz file you uploaded. If you do not see it, try repeating the upload steps from the previous section.
Click the "New File" button. Call the file Compress.php.
Enter the following code into the Compress.php file (please type the filename that matches your .tar.gz file):
<?php
exec("tar czvf allmyfiles.tar.gz *");
?>
Then, save the file.
We'll need to use "CHMOD" from within the File Manager to change the permissions so we can execute this script. Click the checkbox next to Ccompress.php and then click the CHMOD button.
You will need to set the Compress.php to mode 755 (User R - W - X - Group R - X - Other R - X). Click "Confirm" after you have checked the appropriate permissions.
Now, you need to run the script by visiting Compress.php with your web browser, go to:
http://www.example.com/downloads/Compress.php
...replacing example.com with your Domain name. It may take a minute to decompress the file. Be patient while the web page loads, it will not finish loading until the file is decompressed. You should then see a blank screen.
Refresh the folder view in File Manager. You should see a file test in YourMainFolder/downloadFolder.
http://www.atyafonline.com/vb/imgcache/887.png
For security, Delete the Compress.php file. so no budy can use it after you.
Decompressing the Package
Create /downloadFolderinside /YourMainFolder
At this point, you have either used FTP to send the file to your web space, or used File Manager. The tar.gz file should now be in http://yourdomain/YourMainFolder/downloadFolder.
We will need to decompress the tar.gz package in order to use the software. To decompress the file, we will need to create either a PHP script (preferred) or Perl script.
To create the PHP script, you will need to create a New File with File Manager (or upload the completed text file with FTP). To create a New File in File Manager:
Log in to the CPanel (https://login.yourdomain.com/), then click "File Manager." (...if you are not already logged in to File Manager.)
If you are not yet in the YourDomain/YourMainFolder/downloadFolder folder, select the YourMainFolder link, and then the downloadFolder link on the following page.
You will now see the .tar.gz file you uploaded. If you do not see it, try repeating the upload steps from the previous section.
Click the "New File" button. Call the file decompress.php.
Enter the following code into the decompress.php file (please type the filename that matches your .tar.gz file):
<?php
exec("tar xzf allmyfiles.tar.gz");
?>
Then, save the file.
We'll need to use "CHMOD" from within the File Manager to change the permissions so we can execute this script. Click the checkbox next to decompress.php and then click the CHMOD button.
You will need to set the decompress.php to mode 755 (User R - W - X - Group R - X - Other R - X). Click "Confirm" after you have checked the appropriate permissions.
Now, you need to run the script by visiting decompress.php with your web browser, go to:
http://www.example.com/downloads/decompress.php
...replacing example.com with your Domain name. It may take a minute to decompress the file. Be patient while the web page loads, it will not finish loading until the file is decompressed. You should then see a blank screen.
Refresh the folder view in File Manager. You should see a folder in YourMainFolder/downloadFolder.
http://www.atyafonline.com/vb/imgcache/887.png
For security, Delete the decompress.php file. so no budy can use it after you.
http://support.globat.com/sc/index.php/Movable_Type
In computing (http://en.wikipedia.org/wiki/Computing), tar (derived from tape archive) is both a file format (http://en.wikipedia.org/wiki/File_format) (in the form of a type of archive (http://en.wikipedia.org/wiki/Archive_formats) bitstream (http://en.wikipedia.org/wiki/Bitstream)) and the name of the program used to handle such files. The format was standardized by POSIX (http://en.wikipedia.org/wiki/POSIX).1-1988 and later POSIX.1-2001. Initially developed as a raw format, used for tape backup (http://en.wikipedia.org/wiki/Tape_backup) and other sequential access (http://en.wikipedia.org/wiki/Sequential_access) devices for backup (http://en.wikipedia.org/wiki/Backup) purposes, it is now commonly used to collate collections of files into one larger file, for distribution (http://en.wikipedia.org/wiki/Distribution_%28software%29) or archiving (http://en.wikipedia.org/wiki/Archiving), while preserving file system (http://en.wikipedia.org/wiki/File_system) information such as user and group permissions, dates, and directory (http://en.wikipedia.org/wiki/Directory_%28file_systems%29) structures.
Contents
[hide (http://javascript%3cb%3e%3c/b%3E:toggleToc%28%29)]
1 Design (http://en.wikipedia.org/wiki/Tar_%28file_format%29#Design)
2 Format details (http://en.wikipedia.org/wiki/Tar_%28file_format%29#Format_details)
2.1 File header (http://en.wikipedia.org/wiki/Tar_%28file_format%29#File_header)
3 Command examples (http://en.wikipedia.org/wiki/Tar_%28file_format%29#Command_examples)
3.1 To create a Tar file (http://en.wikipedia.org/wiki/Tar_%28file_format%29#To_create_a_Tar_file)
3.2 To list files in a compressed Tar file (http://en.wikipedia.org/wiki/Tar_%28file_format%29#To_list_files_in_a_compresse d_Tar_file)
3.3 To extract files from a Tar file (http://en.wikipedia.org/wiki/Tar_%28file_format%29#To_extract_files_from_a_Tar_ file)
3.4 UStar format (http://en.wikipedia.org/wiki/Tar_%28file_format%29#UStar_format)
3.5 Example (http://en.wikipedia.org/wiki/Tar_%28file_format%29#Example)
4 Naming of tar archive files (http://en.wikipedia.org/wiki/Tar_%28file_format%29#Naming_of_tar_archive_files)
5 tarbombs (http://en.wikipedia.org/wiki/Tar_%28file_format%29#tarbombs)
6 tarpipe (http://en.wikipedia.org/wiki/Tar_%28file_format%29#tarpipe)
6.1 Remote tarpipe (http://en.wikipedia.org/wiki/Tar_%28file_format%29#Remote_tarpipe)
7 tarpit (http://en.wikipedia.org/wiki/Tar_%28file_format%29#tarpit)
8 See also (http://en.wikipedia.org/wiki/Tar_%28file_format%29#See_also)
9 Notes (http://en.wikipedia.org/wiki/Tar_%28file_format%29#Notes)
10 External links (http://en.wikipedia.org/wiki/Tar_%28file_format%29#External_links)
Design
tar's linear roots can still be seen in its ability to work on any data stream and its slow partial extraction performance, as it has to read through the whole archive to extract only the final file. A tar file (somefile.tar), when subsequently compressed using a compression (http://en.wikipedia.org/wiki/Data_compression) utility such as gzip (http://en.wikipedia.org/wiki/Gzip), bzip2 (http://en.wikipedia.org/wiki/Bzip2), lzma (http://en.wikipedia.org/wiki/Lzma) or compress (http://en.wikipedia.org/wiki/Compress), produces a compressed tar file with a filename extension indicating the type of compression (e.g.: somefile.tar.gz). A .tar file is commonly referred to as a tarball, which is usually compressed to save disk space.
As is common with Unix utilities, tar is a single specialist program. It follows the Unix philosophy (http://en.wikipedia.org/wiki/Unix_philosophy) in that it can "do only one thing" (archive), "but do it well". tar is most commonly used in tandem with an external compression utility, since it has no built-in data compression (http://en.wikipedia.org/wiki/Data_compression) facilities. These compression utilities generally only compress a single file, hence the pairing with tar, which can produce a single file from many files. To ease this common usage, the BSD (http://en.wikipedia.org/wiki/BSD) and GNU (http://en.wikipedia.org/wiki/GNU) versions of tar support the command line options (http://en.wikipedia.org/wiki/Command_line_option) -z (gzip), and -j (bzip2) which will compress or decompress the archive file it is currently working with. Both will also extract compressed archives without requiring these options. With the GNU (http://en.wikipedia.org/wiki/GNU) version, the (de)compression is actually performed by an external program.
Format details
A tar file is the concatenation of one or more files. Each file is preceded by a header (http://en.wikipedia.org/wiki/Header_%28information_technology%29) block. The file data is written unaltered except that its length is rounded up to a multiple of 512 bytes and the extra space is zero filled. The end of an archive is marked by at least two consecutive zero-filled blocks.
A limitation of early tape drives was that data could only be written to them in 512 byte blocks[citation needed (http://en.wikipedia.org/wiki/Wikipedia:Citation_needed)]. As a result data in tar files is arranged in 512 byte blocks.
The tar command can write data to tape in chunks of several 512 byte blocks, to minimize the wasted gaps in the tape between write operations. Each chunk is called a record. The user can specify a blocking factor, which is the number of blocks per record. The end of an archive gets padded with additional blocks of zeros to make its total size equal a multiple of records, regardless of whether tape is used as the storage medium.
File header
The file header block contains metadata (http://en.wikipedia.org/wiki/Metadata) about a file. To ensure portability across different architectures with different byte orderings (http://en.wikipedia.org/wiki/Endianness), the information in the header block is encoded in ASCII (http://en.wikipedia.org/wiki/ASCII). Thus if all the files in an archive are text files, then the archive is essentially an ASCII file.
The fields defined by the original Unix tar format are listed in the table below. When a field is unused it is zero filled. The header is padded with zero bytes to make it up to a 512 byte block.
Field Offset Field Size Field 0 100 File name 100 8 File mode 108 8 Owner user ID 116 8 Group user ID 124 12 File size in bytes (octal) 136 12 Last modification time 148 8 Check sum for header block 156 1 Link indicator 157 100 Name of linked file
Field Offset Field Size Field
0 100 File name
100 8 File mode
108 8 Owner user ID
116 8 Group user ID
124 12 File size in bytes (octal)
136 12 Last modification time
148 8 Check sum for header block
156 1 Link indicator
157 100 Name of linked file
Link indicator field
Value Meaning
'0' Normal file
(ASCII NUL)[1] Normal file
'1' Hard link
'2' Symbolic link[2]
'3' Character special
'4' Block special
'5' Directory
'6' FIFO
'7' Contiguous file[3]
A directory is also indicated by having a trailing slash (/) in the name.
For historical reasons numerical values are encoded in as ASCII text octal (http://en.wikipedia.org/wiki/Octal) numbers, with leading zeroes. The final character is either a null (http://en.wikipedia.org/wiki/Null) or a space (http://en.wikipedia.org/wiki/Space_%28punctuation%29). Thus although there are 12 bytes reserved for storing the file size, only 11 octal digits can be stored. This gives a maximum file size of 8 gigabytes (http://en.wikipedia.org/wiki/Gigabyte) on archived files. To overcome this limitation some versions of tar, including the GNU (http://en.wikipedia.org/wiki/GNU) implementation, support an extension in which the file size is encoded in binary. Additionally, versions of GNU tar from 1999 and before pad the values with whitespace (http://en.wikipedia.org/wiki/Whitespace) characters instead of zero characters.
The checksum is calculated by taking the sum of the byte values of the header block with the eight checksum bytes taken to be ascii spaces (value 32). It is stored as a six digit octal number with leading zeroes followed by a null and then a space.
Command examples
Some simple examples of using the Tar program.
To create a Tar file
Creates a GZIP-compressed Tar file named allmyfiles.tar.gz of all files with a .txt suffix:
tar -czvf allmyfiles.tar.gz *.txt
To list files in a compressed Tar file
tar -tzf allmyfiles.tar.gz
To extract files from a Tar file
Extracts all files from a compressed Tar file named eglinux.tar.gz.
tar -xvf allmyfiles.tar.gz
<?php
print " Pleas holdon for Unzip the files.";
exec("tar -xzvf allmyfiles.tar.gz");
print "Done from Unzipping the files.";
print "Thanks see you next Unzipping : ) bye";
?>
Extracts to a specific folder:
tar -xvf allmyfiles.tar.gz -C ~/des
Other versions of Tar may require the -z option to specify the compression type.
UStar format
Most modern tar programs read and write archives in the new UStar (http://en.wikipedia.org/w/index.php?title=UStar&action=edit&redlink=1) (Uniform Standard Tape Archive) format, which has an extended header definition as defined by the POSIX (IEEE P1003.1) standards group. Older tar programs will ignore the extra information, while newer programs will test for the presence of the "ustar" string to determine if the new format is in use. The UStar format allows for longer file names and stores extra information about each file.
Field Offset Field Size Field
0 156 (as in old format)
156 1 Type flag
157 100 (as in old format)
257 6 UStar indicator "ustar"
263 2 UStar version "00"
265 32 Owner user name
297 32 Owner group name
329 8 Device major number
337 8 Device minor number
345 155 Filename prefix
Example
The example below shows the ASCII (http://en.wikipedia.org/wiki/ASCII) dump of a header block from a tar file created using the GNU tar program. It was dumped with the od (http://en.wikipedia.org/wiki/Od_%28Unix%29) program. The "ustar" magic string followed by two spaces can be seen, meaning that the tar file is in GNU format, partially incompatible with the true UStar standard (in POSIX.1-1988), which has the signature "ustar" followed by a NUL character.[4] (http://en.wikipedia.org/wiki/Tar_%28file_format%29#cite_note-3)
Naming of tar archive files
Like most Unix utilities, tar doesn't require any particular filename suffix in order to recognize a file as an archive. Conventionally, uncompressed tar archive files have names ending in ".tar". If an archive is compressed with an external tool, the compression program adds its own suffix as usual, resulting in filename endings like ".tar.Z", ".tar.gz", and ".tar.bz2".
Names like those can't exist on MS-DOS (http://en.wikipedia.org/wiki/MS-DOS) due to its 8.3 filename limitations (http://en.wikipedia.org/wiki/8.3_filename), so a second set of conventions appeared for storing compressed tar archives on an MS-DOS file system:
".tgz" is equivalent to ".tar.gz".
".tbz" (or ".tbz2" or ".tb2") is equivalent to ".tar.bz2".
".taz" is equivalent to ".tar.Z",
These shortened filename suffixes are still in common use.
tarbombs
Not to be confused with decompression bomb (http://en.wikipedia.org/wiki/Decompression_bomb).
tarbomb is derogatory hacker slang (http://en.wikipedia.org/wiki/Hacker_slang) used to refer to a tarball containing files that untar to the current directory instead of untarring into a directory of their own. This can be a potential problem if it overwrites files using the same name in the current directory. It can also be a pain for the user who then needs to delete all the files that are scattered over the directory amongst other files. Often this ends up happening in the user's home directory. Such behaviour is often considered bad etiquette on the part of the archive's creator.
tarpipe
A tarpipe is the process of creating a tar archive in stdout and then, in another directory, extracting the tar file from the piped stdin. This is a useful way to copy directories and subdirectories, especially if the directories contain special files, such as symlinks, and character or block devices.
tar -cf - "${srcdir}" | ( cd "${destdir}" && tar -xvf - )
Remote tarpipe
A remote tarpipe or ssh tarpipe uses the same methodology of a tarpipe, but instead of simply changing to a new directory on the local host to extract the tar, the user logs into a remote host in order to execute the tar extraction.
tar -cf - "${srcdir}" | ssh ${user}@${remotehost} "cd ${destdir} && tar -xvf
tarpit
tarpit is a term to describe a method of revision control where a tar is used to capture the state of development of a software module at a particular point in time. The use of a tarpit typically loosely mirrors the use of a revision control (http://en.wikipedia.org/wiki/Revision_control) software tag and branching through the use of descriptive names.
http://en.wikipedia.org/wiki/Tar_(file_format (http://en.wikipedia.org/wiki/Tar_%28file_format))
Quick Tips: How to copy/archive a site with only FTP access (http://baheyeldin.com/technology/drupal/quick-tips-how-copyarchive-drupal-site-only-ftp-access.html)
Submitted by Khalid on Sat, 2008/07/05 - 01:46
I do most of my work using ssh and other command line tools, such as vim (http://en.wikipedia.org/wiki/Vim_%28text_editor%29) and screen (http://en.wikipedia.org/wiki/GNU_Screen). This is the environment I am most comfortable and productive in.
However, this is not always an option working on client sites. Some do not have ssh enabled for various reasons, including hosting restrictions (e.g. shared hosting) or security concerns and workplace policies.
So, in these situations, it is hard to replicate the site on a test server for an assessment, development work, or moving the site from an old server to a new one.
The following are some techniques that I use when I need to copy a site quickly.
Using cPanel
If the site in question has cPanel, you can use phpMyAdmin (http://en.wikipedia.org/wiki/Phpmyadmin) to backup the database, and either save it to a file, or directly download it to your desktop. That takes care of the database part, what about the files then?
For the files, you can use cPanel's cron interface to run a command like the following after 2 minutes from present time:
cd ~/public_html; tar -czvf BACKUP.tar.gz .
Wait for the two minutes to pass, then using FTP or cPanel's File Manager, download the archive that was created.
Using a temporary PHP script
Instead of using web based interfaces, which can be clumsy, you can use FTP to upload a custom PHP script that executes shell commands on your behalf.
First, download the settings.php file for the site. In it, there will be the database name, the use name and password for the site.
Second, take the above information and create a PHP file like this one. Replace the capitalized values with those you just gleaned from the settings file.
<?php
exec("mysqldump -uDBUSER -pPASSWORD DBNAME > DBNAME.sql");
exec("tar -czvf BACKUP.tar.gz .");
print "Done from Backuping allmyfiles";
print "Thanks see you next Backup";
?>
<?php
exec("mysqldump -uDatabaseUSERName -pDatabasePASSWORD DatabaseNAME > allmyDatabaseBackup$(date +"%Y%m%d").sql");
print "Done from Backuping allmyDataBase Specified";
exec("tar -czvf allmyfiles$(date +"%Y%m%d").tar.gz *");
print "Done from Backuping allmyfiles";
print "Thanks see you next Backup :) bye";
?>
Name the file something unique and unguessable, such as a timestamp or a random number (e.g. 74688266024.php). Make sure that it ends in .php.
Upload this file using FTP to the public_html directory for your site. Then point your browser to it (e.g. http://example.com/74688266024.php), and wait till the backup completes.
Now, delete the php file you just created, so no one else can run the script.
After that, download the tar achive using FTP, and delete it and the database dump too.
http://baheyeldin.com/technology/drupal/quick-tips-how-copyarchive-drupal-site-only-ftp-access.html
To find files
To automatically uncompress a bunch of .tar.gz files within a directory.
find -name '*.tar.gz' -exec tar xzvf '{}' ';'
To find files recursively in sub directories, if any.
If you only want files in the current directory, you can use:
for i in *.tar.gz;
do tar xzvf $i;
done
http://www.webhostingtalk.com/showthread.php?t=672543
If it unzips each into a new directory, just cd into that directory and do for loop like:
Code:
for FILE in `ls`
do
tar xzvf $FILE
done
To find all the tar.gz including those in subdirectories and unzip them all.
1. cd into the directory where all the tar.gz files are located.
2. Run:
find . -type f -name *.tar.gz -exec tar xzvf {} \;
First, de-tar the file:
Code:
tar zxvf allmyfiles.tar.gz
...now you have all these .gz files we have to gunzip them. This method will recurse into sub-directories, and will work even if the file/directory names include spaces and other weird characters. It also prints
verbose information about what it is doing, which is nice if there is a really large amount of work to do because you can see that it's still working even if it takes a while:
Code:
find . -type f -iname \*.gz -print0 |xargs -0 gunzip -v
If you have multiple processors, you can use the -P *max-procs* option to xargs to run multiple instances of gunzip in parallel. There's no point if you only have one CPU (in fact it'll probably run slower). You should also leave some CPU for IO work. So if you have 4 CPUs, try:
Code:
find . -type f -iname \*.gz -print0 |xargs -0 -P 3 gunzip -v
...which will tun 3 parallel gunzip's together, leaving one CPU for IO and other work. Of course, this is only really going to be noticeable if the amount of gunzipping is very large...
https://www.linuxquestions.org/questions/linux-general-1/tar-zxvf-foo.tar.gz-creates-all-.gz-files-499529/
tar czfv Test.tar.gz Test/
czfv = ‘Compress Zip File Verbose’
If you want bzip files, use ‘j’ instead of ‘z’.
Uncompress Test.tar.gz to folder Test/
tar -xzvf Test.tar.gz
x = ‘eXtract’
Again, if you want bzip files, use ‘j’ instead of ‘z’.
Archive Contents (http://txt.binnyva.com/2008/07/archive-contents/)
Show contents of an archive
tar -tf archive.tar
http://txt.binnyva.com/2007/02/command-to-compressuncompress-targz-and-tarbz2-files/
if you want to make a file with a 2GB maximum you wauld hove:
tar czvf -L 2 allmyfiles.tar.gz myfile
http://www.linuxforums.org/forum/linux-newbie/29236-making-tar-gz-file-linux.html
To put everything in the D folder into a tar file in the backup folder.
For .tar.gz:
sudo tar -czf /home/backup/D_backup$(date +"%Y%m%d").tar.gz /home/D
For .tar.bz2 (higher compression, takes longer):
sudo tar -cjf /home/backup/D_backup$(date +"%Y%m%d").tar.bz2 /home/D
You might want to read up on gpg for the encryption.
http://ubuntuforums.org/showthread.php?t=573290
Backup and split archive with tar
If you want to use tar, try something like this:
tar -cvlf - / | split -a 2 -b 2000m - /mnt/big_backup.tar
You must specify the -l switch for tar, so it stays within one filesystem. Otherwise it'll try to backup the backup file that split just created! This also means you'll have to create a separate backup for each partition that you have.
Now, you have several files /mnt/big_backup.tarxx,
how can you extract them ? http://www.atyafonline.com/vb/imgcache/891.png
tried this:
tar -cv --exclude "/mnt" -f - / | split -a 2 -b 2000m - /mnt/big_backup.tar
or
cat big_backup.tar* | tar -tvf - ought to do it.
http://forums.bsdnexus.com/viewtopic.php?id=403
Tar.gz - A Quick and Easy Compression and Extraction Command Line
Sun, 2007-05-13 00:36 — keith
http://www.atyafonline.com/vb/imgcache/886.png
What I am going to do next is to introduce a very simple, quick and easy way of compression (zipping) and decompression (extracting) files using command line. This may be relatively easy to many users, especially to Linux experts. However, not everyone is an expert in that sense.
Learning to use command line to archive files can be a very beneficial. First of all, it does not use Graphical User Interface (GUI), therefore there is more resources made available for your systems (instead of using them on GUIs). Secondly, you are able to access remote systems using Secure Shell (SSH) connections and perform tasks on the remote systems, as though they are directly on your systems; that is, for example accessing web hosting servers via SSH to backup your web sites (although I know backup functions do exist in cPanel). Well, the list may still continue, but I shall stop here.
(learn more by clicking here... (http://www.neohide.com/tar-gz-a-quick-and-easy-compression-and-extraction-command-line))
Creating An Archive
Assume you are on a text console, and you would like to zip up a folder at your current directory say "abcfolder", simply run the following command:
tar czvf myfolder.tar.gz abcfolder/
The above command creates an archive file name, myfolder.tar.gz. Everything under the directory abcfolder/ will be compressed and stored.
To compress all the files within a folder:
tar czvf allmyfiles.tar.gz *
The above command thus compresses all the files (including subfolders) within the directory and archived it as allmyfiles.tar.gz.
Basically, there are various variants you can play around with tar command in Linux. All you need is to type "man tar" to find out more information. So next, let's extract these files.
Extracting Files from Archive
Extracting is probably quite easy. If you have a .tar.gz file, simply type the command to extract all the files and folders to the current folder you are in.
tar -xzvf extractme.tar.gz
The above command extracts the archive, extractme.tar.gz to your current folder or directory.
So, you see, it's not really that difficult to use compress and uncompress files and folders in linux via command line. It's time to throw away some of GUIs.
http://www.neohide.com/tar-gz-a-quick-and-easy-compression-and-extraction-command-line
Compressing the Package
Create /downloadFolderinside /YourMainFolder
At this point, you have either used FTP to send the file to your web space, or used File Manager. The tar.gz file should now be in http://yourdomain/YourMainFolder/downloadFolder.
We will need to decompress the tar.gz package in order to use the software. To decompress the file, we will need to create either a PHP script (preferred) or Perl script.
To create the PHP script, you will need to create a New File with File Manager (or upload the completed text file with FTP). To create a New File in File Manager:
Log in to the CPanel (https://login.yourdomain.com/), then click "File Manager." (...if you are not already logged in to File Manager.)
If you are not yet in the YourDomain/YourMainFolder/downloadFolder folder, select the YourMainFolder link, and then the downloadFolder link on the following page.
You will now see the .tar.gz file you uploaded. If you do not see it, try repeating the upload steps from the previous section.
Click the "New File" button. Call the file Compress.php.
Enter the following code into the Compress.php file (please type the filename that matches your .tar.gz file):
<?php
exec("tar czvf allmyfiles.tar.gz *");
?>
Then, save the file.
We'll need to use "CHMOD" from within the File Manager to change the permissions so we can execute this script. Click the checkbox next to Ccompress.php and then click the CHMOD button.
You will need to set the Compress.php to mode 755 (User R - W - X - Group R - X - Other R - X). Click "Confirm" after you have checked the appropriate permissions.
Now, you need to run the script by visiting Compress.php with your web browser, go to:
http://www.example.com/downloads/Compress.php
...replacing example.com with your Domain name. It may take a minute to decompress the file. Be patient while the web page loads, it will not finish loading until the file is decompressed. You should then see a blank screen.
Refresh the folder view in File Manager. You should see a file test in YourMainFolder/downloadFolder.
http://www.atyafonline.com/vb/imgcache/887.png
For security, Delete the Compress.php file. so no budy can use it after you.
Decompressing the Package
Create /downloadFolderinside /YourMainFolder
At this point, you have either used FTP to send the file to your web space, or used File Manager. The tar.gz file should now be in http://yourdomain/YourMainFolder/downloadFolder.
We will need to decompress the tar.gz package in order to use the software. To decompress the file, we will need to create either a PHP script (preferred) or Perl script.
To create the PHP script, you will need to create a New File with File Manager (or upload the completed text file with FTP). To create a New File in File Manager:
Log in to the CPanel (https://login.yourdomain.com/), then click "File Manager." (...if you are not already logged in to File Manager.)
If you are not yet in the YourDomain/YourMainFolder/downloadFolder folder, select the YourMainFolder link, and then the downloadFolder link on the following page.
You will now see the .tar.gz file you uploaded. If you do not see it, try repeating the upload steps from the previous section.
Click the "New File" button. Call the file decompress.php.
Enter the following code into the decompress.php file (please type the filename that matches your .tar.gz file):
<?php
exec("tar xzf allmyfiles.tar.gz");
?>
Then, save the file.
We'll need to use "CHMOD" from within the File Manager to change the permissions so we can execute this script. Click the checkbox next to decompress.php and then click the CHMOD button.
You will need to set the decompress.php to mode 755 (User R - W - X - Group R - X - Other R - X). Click "Confirm" after you have checked the appropriate permissions.
Now, you need to run the script by visiting decompress.php with your web browser, go to:
http://www.example.com/downloads/decompress.php
...replacing example.com with your Domain name. It may take a minute to decompress the file. Be patient while the web page loads, it will not finish loading until the file is decompressed. You should then see a blank screen.
Refresh the folder view in File Manager. You should see a folder in YourMainFolder/downloadFolder.
http://www.atyafonline.com/vb/imgcache/887.png
For security, Delete the decompress.php file. so no budy can use it after you.
http://support.globat.com/sc/index.php/Movable_Type
In computing (http://en.wikipedia.org/wiki/Computing), tar (derived from tape archive) is both a file format (http://en.wikipedia.org/wiki/File_format) (in the form of a type of archive (http://en.wikipedia.org/wiki/Archive_formats) bitstream (http://en.wikipedia.org/wiki/Bitstream)) and the name of the program used to handle such files. The format was standardized by POSIX (http://en.wikipedia.org/wiki/POSIX).1-1988 and later POSIX.1-2001. Initially developed as a raw format, used for tape backup (http://en.wikipedia.org/wiki/Tape_backup) and other sequential access (http://en.wikipedia.org/wiki/Sequential_access) devices for backup (http://en.wikipedia.org/wiki/Backup) purposes, it is now commonly used to collate collections of files into one larger file, for distribution (http://en.wikipedia.org/wiki/Distribution_%28software%29) or archiving (http://en.wikipedia.org/wiki/Archiving), while preserving file system (http://en.wikipedia.org/wiki/File_system) information such as user and group permissions, dates, and directory (http://en.wikipedia.org/wiki/Directory_%28file_systems%29) structures.
Contents
[hide (http://javascript%3cb%3e%3c/b%3E:toggleToc%28%29)]
1 Design (http://en.wikipedia.org/wiki/Tar_%28file_format%29#Design)
2 Format details (http://en.wikipedia.org/wiki/Tar_%28file_format%29#Format_details)
2.1 File header (http://en.wikipedia.org/wiki/Tar_%28file_format%29#File_header)
3 Command examples (http://en.wikipedia.org/wiki/Tar_%28file_format%29#Command_examples)
3.1 To create a Tar file (http://en.wikipedia.org/wiki/Tar_%28file_format%29#To_create_a_Tar_file)
3.2 To list files in a compressed Tar file (http://en.wikipedia.org/wiki/Tar_%28file_format%29#To_list_files_in_a_compresse d_Tar_file)
3.3 To extract files from a Tar file (http://en.wikipedia.org/wiki/Tar_%28file_format%29#To_extract_files_from_a_Tar_ file)
3.4 UStar format (http://en.wikipedia.org/wiki/Tar_%28file_format%29#UStar_format)
3.5 Example (http://en.wikipedia.org/wiki/Tar_%28file_format%29#Example)
4 Naming of tar archive files (http://en.wikipedia.org/wiki/Tar_%28file_format%29#Naming_of_tar_archive_files)
5 tarbombs (http://en.wikipedia.org/wiki/Tar_%28file_format%29#tarbombs)
6 tarpipe (http://en.wikipedia.org/wiki/Tar_%28file_format%29#tarpipe)
6.1 Remote tarpipe (http://en.wikipedia.org/wiki/Tar_%28file_format%29#Remote_tarpipe)
7 tarpit (http://en.wikipedia.org/wiki/Tar_%28file_format%29#tarpit)
8 See also (http://en.wikipedia.org/wiki/Tar_%28file_format%29#See_also)
9 Notes (http://en.wikipedia.org/wiki/Tar_%28file_format%29#Notes)
10 External links (http://en.wikipedia.org/wiki/Tar_%28file_format%29#External_links)
Design
tar's linear roots can still be seen in its ability to work on any data stream and its slow partial extraction performance, as it has to read through the whole archive to extract only the final file. A tar file (somefile.tar), when subsequently compressed using a compression (http://en.wikipedia.org/wiki/Data_compression) utility such as gzip (http://en.wikipedia.org/wiki/Gzip), bzip2 (http://en.wikipedia.org/wiki/Bzip2), lzma (http://en.wikipedia.org/wiki/Lzma) or compress (http://en.wikipedia.org/wiki/Compress), produces a compressed tar file with a filename extension indicating the type of compression (e.g.: somefile.tar.gz). A .tar file is commonly referred to as a tarball, which is usually compressed to save disk space.
As is common with Unix utilities, tar is a single specialist program. It follows the Unix philosophy (http://en.wikipedia.org/wiki/Unix_philosophy) in that it can "do only one thing" (archive), "but do it well". tar is most commonly used in tandem with an external compression utility, since it has no built-in data compression (http://en.wikipedia.org/wiki/Data_compression) facilities. These compression utilities generally only compress a single file, hence the pairing with tar, which can produce a single file from many files. To ease this common usage, the BSD (http://en.wikipedia.org/wiki/BSD) and GNU (http://en.wikipedia.org/wiki/GNU) versions of tar support the command line options (http://en.wikipedia.org/wiki/Command_line_option) -z (gzip), and -j (bzip2) which will compress or decompress the archive file it is currently working with. Both will also extract compressed archives without requiring these options. With the GNU (http://en.wikipedia.org/wiki/GNU) version, the (de)compression is actually performed by an external program.
Format details
A tar file is the concatenation of one or more files. Each file is preceded by a header (http://en.wikipedia.org/wiki/Header_%28information_technology%29) block. The file data is written unaltered except that its length is rounded up to a multiple of 512 bytes and the extra space is zero filled. The end of an archive is marked by at least two consecutive zero-filled blocks.
A limitation of early tape drives was that data could only be written to them in 512 byte blocks[citation needed (http://en.wikipedia.org/wiki/Wikipedia:Citation_needed)]. As a result data in tar files is arranged in 512 byte blocks.
The tar command can write data to tape in chunks of several 512 byte blocks, to minimize the wasted gaps in the tape between write operations. Each chunk is called a record. The user can specify a blocking factor, which is the number of blocks per record. The end of an archive gets padded with additional blocks of zeros to make its total size equal a multiple of records, regardless of whether tape is used as the storage medium.
File header
The file header block contains metadata (http://en.wikipedia.org/wiki/Metadata) about a file. To ensure portability across different architectures with different byte orderings (http://en.wikipedia.org/wiki/Endianness), the information in the header block is encoded in ASCII (http://en.wikipedia.org/wiki/ASCII). Thus if all the files in an archive are text files, then the archive is essentially an ASCII file.
The fields defined by the original Unix tar format are listed in the table below. When a field is unused it is zero filled. The header is padded with zero bytes to make it up to a 512 byte block.
Field Offset Field Size Field 0 100 File name 100 8 File mode 108 8 Owner user ID 116 8 Group user ID 124 12 File size in bytes (octal) 136 12 Last modification time 148 8 Check sum for header block 156 1 Link indicator 157 100 Name of linked file
Field Offset Field Size Field
0 100 File name
100 8 File mode
108 8 Owner user ID
116 8 Group user ID
124 12 File size in bytes (octal)
136 12 Last modification time
148 8 Check sum for header block
156 1 Link indicator
157 100 Name of linked file
Link indicator field
Value Meaning
'0' Normal file
(ASCII NUL)[1] Normal file
'1' Hard link
'2' Symbolic link[2]
'3' Character special
'4' Block special
'5' Directory
'6' FIFO
'7' Contiguous file[3]
A directory is also indicated by having a trailing slash (/) in the name.
For historical reasons numerical values are encoded in as ASCII text octal (http://en.wikipedia.org/wiki/Octal) numbers, with leading zeroes. The final character is either a null (http://en.wikipedia.org/wiki/Null) or a space (http://en.wikipedia.org/wiki/Space_%28punctuation%29). Thus although there are 12 bytes reserved for storing the file size, only 11 octal digits can be stored. This gives a maximum file size of 8 gigabytes (http://en.wikipedia.org/wiki/Gigabyte) on archived files. To overcome this limitation some versions of tar, including the GNU (http://en.wikipedia.org/wiki/GNU) implementation, support an extension in which the file size is encoded in binary. Additionally, versions of GNU tar from 1999 and before pad the values with whitespace (http://en.wikipedia.org/wiki/Whitespace) characters instead of zero characters.
The checksum is calculated by taking the sum of the byte values of the header block with the eight checksum bytes taken to be ascii spaces (value 32). It is stored as a six digit octal number with leading zeroes followed by a null and then a space.
Command examples
Some simple examples of using the Tar program.
To create a Tar file
Creates a GZIP-compressed Tar file named allmyfiles.tar.gz of all files with a .txt suffix:
tar -czvf allmyfiles.tar.gz *.txt
To list files in a compressed Tar file
tar -tzf allmyfiles.tar.gz
To extract files from a Tar file
Extracts all files from a compressed Tar file named eglinux.tar.gz.
tar -xvf allmyfiles.tar.gz
<?php
print " Pleas holdon for Unzip the files.";
exec("tar -xzvf allmyfiles.tar.gz");
print "Done from Unzipping the files.";
print "Thanks see you next Unzipping : ) bye";
?>
Extracts to a specific folder:
tar -xvf allmyfiles.tar.gz -C ~/des
Other versions of Tar may require the -z option to specify the compression type.
UStar format
Most modern tar programs read and write archives in the new UStar (http://en.wikipedia.org/w/index.php?title=UStar&action=edit&redlink=1) (Uniform Standard Tape Archive) format, which has an extended header definition as defined by the POSIX (IEEE P1003.1) standards group. Older tar programs will ignore the extra information, while newer programs will test for the presence of the "ustar" string to determine if the new format is in use. The UStar format allows for longer file names and stores extra information about each file.
Field Offset Field Size Field
0 156 (as in old format)
156 1 Type flag
157 100 (as in old format)
257 6 UStar indicator "ustar"
263 2 UStar version "00"
265 32 Owner user name
297 32 Owner group name
329 8 Device major number
337 8 Device minor number
345 155 Filename prefix
Example
The example below shows the ASCII (http://en.wikipedia.org/wiki/ASCII) dump of a header block from a tar file created using the GNU tar program. It was dumped with the od (http://en.wikipedia.org/wiki/Od_%28Unix%29) program. The "ustar" magic string followed by two spaces can be seen, meaning that the tar file is in GNU format, partially incompatible with the true UStar standard (in POSIX.1-1988), which has the signature "ustar" followed by a NUL character.[4] (http://en.wikipedia.org/wiki/Tar_%28file_format%29#cite_note-3)
Naming of tar archive files
Like most Unix utilities, tar doesn't require any particular filename suffix in order to recognize a file as an archive. Conventionally, uncompressed tar archive files have names ending in ".tar". If an archive is compressed with an external tool, the compression program adds its own suffix as usual, resulting in filename endings like ".tar.Z", ".tar.gz", and ".tar.bz2".
Names like those can't exist on MS-DOS (http://en.wikipedia.org/wiki/MS-DOS) due to its 8.3 filename limitations (http://en.wikipedia.org/wiki/8.3_filename), so a second set of conventions appeared for storing compressed tar archives on an MS-DOS file system:
".tgz" is equivalent to ".tar.gz".
".tbz" (or ".tbz2" or ".tb2") is equivalent to ".tar.bz2".
".taz" is equivalent to ".tar.Z",
These shortened filename suffixes are still in common use.
tarbombs
Not to be confused with decompression bomb (http://en.wikipedia.org/wiki/Decompression_bomb).
tarbomb is derogatory hacker slang (http://en.wikipedia.org/wiki/Hacker_slang) used to refer to a tarball containing files that untar to the current directory instead of untarring into a directory of their own. This can be a potential problem if it overwrites files using the same name in the current directory. It can also be a pain for the user who then needs to delete all the files that are scattered over the directory amongst other files. Often this ends up happening in the user's home directory. Such behaviour is often considered bad etiquette on the part of the archive's creator.
tarpipe
A tarpipe is the process of creating a tar archive in stdout and then, in another directory, extracting the tar file from the piped stdin. This is a useful way to copy directories and subdirectories, especially if the directories contain special files, such as symlinks, and character or block devices.
tar -cf - "${srcdir}" | ( cd "${destdir}" && tar -xvf - )
Remote tarpipe
A remote tarpipe or ssh tarpipe uses the same methodology of a tarpipe, but instead of simply changing to a new directory on the local host to extract the tar, the user logs into a remote host in order to execute the tar extraction.
tar -cf - "${srcdir}" | ssh ${user}@${remotehost} "cd ${destdir} && tar -xvf
tarpit
tarpit is a term to describe a method of revision control where a tar is used to capture the state of development of a software module at a particular point in time. The use of a tarpit typically loosely mirrors the use of a revision control (http://en.wikipedia.org/wiki/Revision_control) software tag and branching through the use of descriptive names.
http://en.wikipedia.org/wiki/Tar_(file_format (http://en.wikipedia.org/wiki/Tar_%28file_format))
Quick Tips: How to copy/archive a site with only FTP access (http://baheyeldin.com/technology/drupal/quick-tips-how-copyarchive-drupal-site-only-ftp-access.html)
Submitted by Khalid on Sat, 2008/07/05 - 01:46
I do most of my work using ssh and other command line tools, such as vim (http://en.wikipedia.org/wiki/Vim_%28text_editor%29) and screen (http://en.wikipedia.org/wiki/GNU_Screen). This is the environment I am most comfortable and productive in.
However, this is not always an option working on client sites. Some do not have ssh enabled for various reasons, including hosting restrictions (e.g. shared hosting) or security concerns and workplace policies.
So, in these situations, it is hard to replicate the site on a test server for an assessment, development work, or moving the site from an old server to a new one.
The following are some techniques that I use when I need to copy a site quickly.
Using cPanel
If the site in question has cPanel, you can use phpMyAdmin (http://en.wikipedia.org/wiki/Phpmyadmin) to backup the database, and either save it to a file, or directly download it to your desktop. That takes care of the database part, what about the files then?
For the files, you can use cPanel's cron interface to run a command like the following after 2 minutes from present time:
cd ~/public_html; tar -czvf BACKUP.tar.gz .
Wait for the two minutes to pass, then using FTP or cPanel's File Manager, download the archive that was created.
Using a temporary PHP script
Instead of using web based interfaces, which can be clumsy, you can use FTP to upload a custom PHP script that executes shell commands on your behalf.
First, download the settings.php file for the site. In it, there will be the database name, the use name and password for the site.
Second, take the above information and create a PHP file like this one. Replace the capitalized values with those you just gleaned from the settings file.
<?php
exec("mysqldump -uDBUSER -pPASSWORD DBNAME > DBNAME.sql");
exec("tar -czvf BACKUP.tar.gz .");
print "Done from Backuping allmyfiles";
print "Thanks see you next Backup";
?>
<?php
exec("mysqldump -uDatabaseUSERName -pDatabasePASSWORD DatabaseNAME > allmyDatabaseBackup$(date +"%Y%m%d").sql");
print "Done from Backuping allmyDataBase Specified";
exec("tar -czvf allmyfiles$(date +"%Y%m%d").tar.gz *");
print "Done from Backuping allmyfiles";
print "Thanks see you next Backup :) bye";
?>
Name the file something unique and unguessable, such as a timestamp or a random number (e.g. 74688266024.php). Make sure that it ends in .php.
Upload this file using FTP to the public_html directory for your site. Then point your browser to it (e.g. http://example.com/74688266024.php), and wait till the backup completes.
Now, delete the php file you just created, so no one else can run the script.
After that, download the tar achive using FTP, and delete it and the database dump too.
http://baheyeldin.com/technology/drupal/quick-tips-how-copyarchive-drupal-site-only-ftp-access.html
To find files
To automatically uncompress a bunch of .tar.gz files within a directory.
find -name '*.tar.gz' -exec tar xzvf '{}' ';'
To find files recursively in sub directories, if any.
If you only want files in the current directory, you can use:
for i in *.tar.gz;
do tar xzvf $i;
done
http://www.webhostingtalk.com/showthread.php?t=672543
If it unzips each into a new directory, just cd into that directory and do for loop like:
Code:
for FILE in `ls`
do
tar xzvf $FILE
done
To find all the tar.gz including those in subdirectories and unzip them all.
1. cd into the directory where all the tar.gz files are located.
2. Run:
find . -type f -name *.tar.gz -exec tar xzvf {} \;
First, de-tar the file:
Code:
tar zxvf allmyfiles.tar.gz
...now you have all these .gz files we have to gunzip them. This method will recurse into sub-directories, and will work even if the file/directory names include spaces and other weird characters. It also prints
verbose information about what it is doing, which is nice if there is a really large amount of work to do because you can see that it's still working even if it takes a while:
Code:
find . -type f -iname \*.gz -print0 |xargs -0 gunzip -v
If you have multiple processors, you can use the -P *max-procs* option to xargs to run multiple instances of gunzip in parallel. There's no point if you only have one CPU (in fact it'll probably run slower). You should also leave some CPU for IO work. So if you have 4 CPUs, try:
Code:
find . -type f -iname \*.gz -print0 |xargs -0 -P 3 gunzip -v
...which will tun 3 parallel gunzip's together, leaving one CPU for IO and other work. Of course, this is only really going to be noticeable if the amount of gunzipping is very large...
https://www.linuxquestions.org/questions/linux-general-1/tar-zxvf-foo.tar.gz-creates-all-.gz-files-499529/