File Archives, Compression and Transfer

Archiving Files:
The files are achieved to back them up to an external storage media such as tape drive or USB flash drive. The two major archival techniques are discussed below :

The Tar command: It is used to create and extract files from a file archive or any removable media.
The tar command archoves files to and extracts files from a singles .tar file. Tthe default device for a tar file is a magnetic tape.
Syntax: tar functions <archive file> <file names>
Function
Definition
ccreates a new tar file
tList the table of contents to the tar file
xExtracts files from the tar file
fSpecifies archive file or tape device. The default tape device is /dev/rmt/0. If the name of archve file is "-", the tar command reads from standard i/p when reading from a tar archive or writes to the standard output if creating a tar archive.
vExecutes in verbose mode, writes to the standard output
hFollows symbolic links as standard files or directories

Example :
#tar cvf files.tar file1 file2 
The above example archives file1 & file2 into files.tar.


To create an archive which bundles all the files in the current directory that end with .doc into the alldocs.tar file:
tar cvf alldocs.tar *.doc

Third example, to create a tar file named ravi.tar containing all the files from the /ravi directory (and any of its subdirectories):
tar cvf ravi.tar ravi/

You can also create tar files on tape drives or floppy disks, like this:
tar cvfM /dev/fd0 panda Archive the files in the panda directory to floppy disk(s).
tar cvf /dev/rmt0 panda Archive the files in the panda directory to the tape drive.

In these examples, the c, v, and f flags mean create a new archive, be verbose (list files being archived), and write the archive to a file.

To view an archive from a Tape: 
#tar tf /dev/rmt/0

To view an archive from a Archive File: 
#tar tf ravi.tar

To retrieve archive from a Tape :
#tar xvf /dev/rmt/0

To retrieve archive from a Flash Drive:
#volrmmount -i rmdisk0 #mounts the flash drive
#cd /rmdisk/rmdisk0 
#ls
ravi.tar
#cp ravi.tar ~ravi #copies the tar file to user ravi's home dir
#cd ~ravi
#tar xvf ravi.tar #retrieving the archived files

Excluding a particular file from the restore:
Create a file and add the files to be excluded.
#vi excludelist
/moon/a
/moon/b
:wq!
Tar -Xxvf excludelist <destination folder>
X → Excluding 

Disadvantage:
By using TAR we cannot take the backup of file size more than 2GB


The Jar command: The Jar command is used to combine multiple files into a single archive file and compresses it.
Syntax : jar options destination <file names>
Function
Definition
ccreates a new jar file
tList the table of contents to the jar file
xExtracts files from the jar file
fSpecifies the jar file to process. The jar command send data to screen if this option is not specified.
vExecutes in verbose mode, writes to the standard output

Creating a jar archive
#jar cvf /tmp/ravi.jar ravi/
This example, creates a jar file named ravi.jar containing all the files from the /ravi directory(and any of its subdirectories)

Viewing a jar archive
#jar tf ravi.jar

Retrieving a jar archive
#jar xvf ravi.jar

Compressing, viewing & Uncompressing files:
Compress & uncompress files using compress command:
Using compress command
compress [-v] <file name>
The compress command replaces the original file with a new file that has a .Z extension.
Using uncompress command
uncompress -v file1.tar.Z #replaces file1.tar.Z with file1.tar
uncompress -c file.tar.Z | tar tvf - #to view the contents
View compressed file's content:
#uncompress -c files.tar.tz | tar tvf -

View compressed file's content using zcat command:
zcat <file name>
zcat ravi.Z | more
zcat files.tar.Z | tar xvf -
The '-' at the end indicates that the tar command should read tar input from standard input.

Note: If a compressed file is compressed again, its file size increases.
Using 7za command:
For compressing:
7za a file1.7z file1
For decompressing:
7za x file1.7z
Using gzip command:
For compressing:
gzip [-v] <file name>
gzip file1 file2 # compresses file1 and file 2 and replaces the file with extension .gzip
For  decompressing :
gunzip file1.gz #uncompress the file.gz
Note: It performs the same compression as compress command but generally produces smaller files.
'gzcat' command: 
It is used to view compressed files using gzip or compress command:
gzcat <file name>
gzcat file.gz
Using zip command: To compress multiple files into a single archive file.
For compressing:
zip target_filename source_filenames 
zip file.zip file1 file2 file3
For  decompressing : 
unzip <zipfile> # unzip the file

unzip -l <zipfile> #list the files in the zip archive.
It adds .zip extension of no name/extension is give for the zipped file.
Note: The jar command and zip command create files that are compatible with each other. The unzip command can uncompress a jar file and the jar command can uncompress a zip file.

Following table summarizes the various compressing/archiving:

Utility
Compress
View
Uncompress
tar 
tar -cvf Archivedfile.tar <file1 file2 …..>tar -tf Archivedfile.tartar -xvf Archivedfile.tar
jarjar -cvf Archivedfile.tar <file1 file2 …..>jar -tf Archivedfile.tarjar -xvf Archivedfile.tar
compresscompress <filename>zcat filename.Zuncompress <filename>
uncompress -c filename.Z
gzcat filename.Z
gzipgzip file1 file2 …...gzcat filename.gzgunzip filename.gz
zipzip file.zip file1 file2 ….unzip -l file.zipunzip file.zip

jar -tf file.zipjar -xvf file.zip


Performing Remote Connections and File Transfers: 

When a user request for login to a remote host, the remote host searches for the local /etc/passwd file for the entry for the remote user. If no entry exists, the remote user cannot access the system.
The ~/.rhosts:
It provides another authentication procedure to determine if a remote user can access the local host with the identity of a local user. This procedure bypass the password authentication mechanism. Here the rhosts file refers to the remote users rhosts file.
If a user's .rhosts file contain a plus(+) character, then the user is able to login from any known system without providing password. 

Using the rlogin command: To establish a remote login session.
rlogin <Host Name>
rlogin -l <user name> <host name>
rlogin starts a terminal session on the remote host specified as host. The remote host must be running a rlogind service (or daemon) for rlogin to connect to. rlogin uses the standard rhosts authorization mechanism.
When no user name is specified either with the -l option or as part of username@hostname, rlogin connects as the user you are currently logged in as (including either your domain name if you are a domain user or your machine name if you are not a domain user).
Note: If the remote host contains ~/.rhosts file for the user, the password is not prompted.

Running a program on a remote system:

rsh <host name> command
The rsh command works only if a .rhosts file exists for the user because the rsh command does not prompt for a password to authenticate new users. We can also provide the IP address instead of host name.

Example: #rsh host1 ls -l /var

Terminating a Process Remotely by Logging on to a another system:
rlogin <host name>
pkill shell

Using Secure Shell (SSH) remote login:
Syntax: ssh [-l <login name>] <host name> | username@hostname [command]
If the system that user logs in from is listed in /etc/hosts.equiv or /etc/shosts.equiv on the remote system and the user name is same on both the systems, the user is immediately permitted to log in.
If .rhosts or .shosts exists in the user's home directory on remote system and contains entry with the client system and user name on that system, the user is permitted to log in.
Note: The above two types of authentication is normally not allowed as they are not secure.    
Using a telnet Command: To log on to a remote system and work in that environment.
telnet <Host Name>
Note: telnet command always prompts for password and does not uses ~/.rhosts file.
Using Virtual network Computing(VNC):
It provides remote desktop session over the Remote Frame Buffer (RFB). The VNC consists of two components:
1. X VNC server
2. VNC Client for X

Xvnc is an X VNC server that allows sharing a Solaris 10 X windows sessions with another Solaris, Linux or Windows system. Use vncserver command to start or stop an Xvnc server:
vncserver options

Vncviewer is and X VNC Client that allows viewing an X windows session from another Solaris, Linux, or Windows system on Solaris 10 system. Use vncviewer command to establish a connection to an Xvnc srver.
Vncviewer options host:display#

Copying Files or directories : 

Th rcp command: 
To copy files from one host to another.
rcp <sourcer file> <host name>:<destination file>
rcp <host name>:<source file> <destination file>
rcp <host name>:<source file> <host name>:<destination file>
The source file is the original files and the destination file is the copy of it.
It checks for the ~/.rhosts file for access permissions.
Examples: 
#rcp /ravi1/test host2:/ravi
In the above example we are copying the files test into the directory /ravi of remote host host2.
#rcp host2:/ravi2/test /ravi1
In the above example we are copying file test from the remote host host2 to the directory /ravi1.
To copy directories from one host to another.
rcp -r <Source Directory> <Host Name>:<Destination Directory>
Example:
#rcp -r /ravi1 host2:/ravi2
In the above example we are copying the directory /ravi1 from the local host to the dir /ravi2 of the remote host.

The FTP Command:
ftp <host name>
User needs to authenticate for FTP session. For anonymous FTP a valid email address is needed. It does not uses the .rhosts file for authentication. There are two ftp transfer mode:

1. ASCII: Enables to transfer plain files:
It was default mode of ftp in Solaris 8 and earlier version. This mode transfers the plain text files and therefore to transfer binary, image or any non-test files, we have to use bin command to ensure complete data transfer.
Example:
#ftp host2
..
ftp>ascii
..
ftp>lcd ~ravi1
..
ftp>ls
..
test
ftp>get test
..
ftp>bye

For transferring multiple files we use mget and mput commands:
mget: To transfer multiple files from remote system to the current working directory.
mput: To transfer multiple files from local system to a directory in remote host.
prompt: To switch interactive prompting on or off.
Example:
#ftp host2
..
ftp> ls
..
test1
test2
..
ftp> prompt
Interactive mode off
ftp> mget test1 test2
ftp> mput test1 test2
ftp> bye

2. Binary: Enables to transfer binary, image or non-text files
It is default mode in Solaris 9 and later. It enables to transfer binary, image and non-text files. We dont have to use bin command to ensure the complete data transfer.
Example:
#ftp host2
..
ftp> get binarytest.file
..
ftp> bye

The ls and cd command are available at the ftp prompt. 
The 'lcd' command is used to change the current working directory on the local system.
To end and ftp session use exit for bye at ftp prompt.

The following table summarizes the remote commands discussed:


Remote Command
Use
Requirement
Syntax
rloginTo establish a remote login sessionThe remote host must be running a rlogind(or daemon). If the remote host contains ~/.rhosts file for the user, the password is not promptedrlogin <Host Name>

rlogin -l <user name> <host name>
rshTo run commands remotelyThe rsh command works only if a .rhosts file exists for the userrsh <host name> command
telnetTo establish a remote login sessiontelnet command always prompts for password and does not uses ~/ .rhosts filetelnet hostname
sshTo establish a secure remote login sessionIf the remote system is listed in /etc/hosts.equiv or /etc/shosts.equiv and user name is same in local and remote machine, the user is permitted to log in.

If ~/.rhosts or  ~/.shosts exists on remote system and has entry for client system and user name on client system, the user is permitted to log in.
ssh [-l login_name] hostname

ssh user@hostname 
rcpTo copy files from one host to anotherIt checks for the ~/.rhosts file for access permissions.rcp <sourcer file> <host name>:<destination file>

rcp <host name>:<source file> <destination file>

rcp <host name>:<source file> <host name>:<destination file>
ftpRemote File TransferUser needs to authenticate for FTP session. For anonymous FTP a valid email address is needed. It does not uses the .rhosts file for authenticationftp <host name>
get/put filename : For single file transfer
mget/mput file1 file2 …. : For multiple file transfer




No comments:

Post a Comment