File Backup and Compression

Keywords: Linux MySQL rsync ssh shell

. tar

Packing multiple files together and decompressing the packaged files

- z # Compression or decompression via gzip

- c # Create a new jar package

- v # Displays the tar command execution process

- f # Specify the file compression name

- t View the contents of the compressed package without decompressing it __________

- p # Keep the original attributes robust

- P

Exclude files or directories that do not need to be processed when packaging

- h # Packing Soft Connection File Pointing to

- j bzip2 command compression or decompression

- x # pressurized tar package

- C # Unzip to the specified directory

hard-derefrence # Packing Hard Link Files

 

[root@mysql-141 ~]# mkdir -p /test
[root@mysql-141 ~]# touch /test/{01..10}.txt
[root@mysql-141 ~]# ls /test/{01..10}.txt
/test/01.txt  /test/03.txt  /test/05.txt  /test/07.txt  /test/09.txt
/test/02.txt  /test/04.txt  /test/06.txt  /test/08.txt  /test/10.txt
[root@mysql-141 ~]# cd /test/
[root@mysql-141 ~]# tar zvf test.tar.gz /test/
[root@mysql-141 test]# tar ztvf test.tar.gz  -C /tmp/
[root@mysql-141 test]# tar zcvf www.tar.gz ./html/ --exclude=test/A
[root@mysql-141 test]# tar zxf test.tar.gz  

. gzip

The gzip command can't compress directories directly, so it needs to pack a file with tar first, then tar calls gzip to compress.

- d # Add compressed files

- v Display the process of instruction execution

- l # List the content messages of the compressed file

- c

- r # Recursively compress all files in the directory

- t # test to check whether the compressed file is complete

 

[root@mysql-141 test]# ls
01.txt  03.txt  05.txt  07.txt  09.txt
02.txt  04.txt  06.txt  08.txt  10.txt
[root@mysql-141 test]# gzip *.txt
[root@mysql-141 test]# ls
01.txt.gz  03.txt.gz  05.txt.gz  07.txt.gz  09.txt.gz
02.txt.gz  04.txt.gz  06.txt.gz  08.txt.gz  10.txt.gz
[root@mysql-141 test]# gzip -l *.gz
         compressed        uncompressed  ratio uncompressed_name
                 27                   0   0.0% 01.txt
                 27                   0   0.0% 02.txt
                 27                   0   0.0% 03.txt
                 27                   0   0.0% 04.txt
                 27                   0   0.0% 05.txt
                 27                   0   0.0% 06.txt
                 27                   0   0.0% 07.txt
                 27                   0   0.0% 08.txt
                 27                   0   0.0% 09.txt
                 27                   0   0.0% 10.txt
[root@mysql-141 test]# echo >11.txt
[root@mysql-141 test]# ls
01.txt.gz  03.txt.gz  05.txt.gz  07.txt.gz  09.txt.gz  11.txt
02.txt.gz  04.txt.gz  06.txt.gz  08.txt.gz  10.txt.gz
[root@mysql-141 test]# gzip -c 11.txt >11.txt.gz     # Compression Reserved Source Files
[root@mysql-141 test]# ls
01.txt.gz  03.txt.gz  05.txt.gz  07.txt.gz  09.txt.gz  11.txt
02.txt.gz  04.txt.gz  06.txt.gz  08.txt.gz  10.txt.gz  11.txt.gz

. unzip

unzip commands can decompress zip-formatted files compressed by zip commands or other compression software

  

. scp

Copy files between different hosts, Using ssh protocol to ensure the security of replication, scp commands are replicated in full every time, inefficient

  scp [options]  [[user@]host1:]file1 ... [[user@]host2:]file2

- C

- l # Specifies the bandwidth occupied by the transmission

- P port # specified port number transmission

- p Retain the original properties of the file after transmission

- q) does not display the transmission progress bar

- r # Reproduce the entire directory recursively

[root@mysql-141 ~]# ll /etc/services 
-rw-r--r-- 1 root root 641020 Apr 17 09:27 /etc/services
[root@mysql-141 ~]# scp /etc/services 10.0.0.201:/tmp     # Push files to remote servers
The authenticity of host '10.0.0.201 (10.0.0.201)' can't be established
.
RSA key fingerprint is 67:e7:85:b7:bf:4a:01:8c:98:98:87:98:64:27:46:d4.Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.201' (RSA) to the list of known host
s.
root@10.0.0.201's password: 
services                             100%  626KB 626.0KB/s   00:00

[root@centos7 ~]# ll /tmp/services 
-rw-r--r-- 1 root root 641020 Apr 18 13:46 /tmp/services


[root@centos7 ~]# touch /tmp/scp.txt    # Remote Server Creation File
[root@mysql-141 ~]# scp -rp 10.0.0.201:/tmp/scp.txt /tmp/    # Draw files from remote servers to local locations
root@10.0.0.201's password: 
scp.txt                              100%    0     0.0KB/s   00:00    
[root@mysql-141 ~]# ls /tmp/scp.txt -l
-rw-r--r-- 1 root root 0 Apr 18 13:50 /tmp/scp.txt

 

. rsync

Excellent tools for full and incremental synchronous backup of local or remote data mirrors, suitable for multiple operating system platforms

It is a C/S mode service, managed by xinetd port.

rsync has three common modes:

1) Local mode Data transmission is similar to cp life, and av parameters are commonly used.

    rsync [OPTION...] SRC... [DEST]

Source file, target file

2) daemon model#

    Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
User@Host:: Source File, Object File
    Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
Source file User @Host:: Target file

3) Remote shell mode access # is similar to the scp command, except that user and host names need to be established.

    Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]

User@Host: Source File Object File
    Push: rsync [OPTION...] SRC... [USER@]HOST:DEST    

Source File User@Host: Target File

  

- v # Detailed Mode Output Progress Information

- z Compression during transmission to improve transmission efficiency

- a # Transfer files recursively and keep all file attributes

- r Transfer to subdirectories in recursive mode

- l # Retain Soft Connections

- n # Test Options, Simulated Execution

exclude=PATTERN # Specifies excluding file mode that does not need to be transferred

-- exclude-from=file # Reads the list of files to be excluded from the text file

- bwlimit=KBPS Restrict transmission speed

deldete Keep the contents of the target directory consistent with the source directory and delete different files

 

[root@centos7 ~]# rsync -av 10.0.0.141:/tmp/passwd.out /tmp
The authenticity of host '10.0.0.141 (10.0.0.141)' can't be established.
RSA key fingerprint is SHA256:jYke6mtF+s2Hm5yhAOqJbZuM6aMMlZl+XJ3Ada7f0Zk.
RSA key fingerprint is MD5:e0:33:96:70:07:e4:bf:c6:c8:a5:2e:86:9b:6b:2d:62.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.141' (RSA) to the list of known hosts.
root@10.0.0.141's password: 
receiving incremental file list
passwd.out

sent 30 bytes  received 266 bytes  45.54 bytes/sec
total size is 183  speedup is 0.62
[root@centos7 ~]# ls -l /tmp/passwd.out 
-rw-r--r-- 1 root root 183 Apr 17 13:21 /tmp/passwd.out

Posted by TomatoLover on Tue, 07 May 2019 07:00:39 -0700