Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

Compressing, Encrypting, and Sending tar


Streams


The file copy techniques using the tar command in the previous section can
also be used to quickly and securely copy a directory structure across a LAN
or the Internet (using the ssh command). One way to make use of these
techniques is to use the following command line to first compress the contents
of a designated directory and then decompress the compressed and encrypted
archive stream into a designated directory on a remote host:


Click here to view code image
matthew@seymour:~$ tar -cvzf data_folder | ssh remote_host '( cd
~/mybackup_dir; tar -xvzf )'


The tar command is used to create, list, and compress the files in the
directory named data_folder. The output is piped through the ssh
(Secure Shell) command and sent to the remote computer named
remote_host. On the remote computer, the stream is then extracted and
saved in the directory named /mybackup_dir. You are prompted for a
password to send the stream.


Copying Files Using cp


To copy files, you could use the cp command. The general format of the
command when used for simple copying is as follows:


Click here to view code image
matthew@seymour:~$ cp -a source_directory target_directory


The -a argument is the same as -dpR:


-d—Preserves    symbolic    links   (by not dereferencing   them)   and copies  the
files that they point to instead of copying the links.
-p—Preserves all file attributes, if possible. (File ownership might
interfere.)
-R—Copies directories recursively.

You can also use the cp command to quickly replicate directories and retain
permissions by using it with the -avR command-line options. Using these
options preserves file and directory permissions, gives verbose output, and
recursively copies and re-creates subdirectories. You can also create a log of
the backup during the backup by redirecting the standard output like this:

Free download pdf