Centos Backup Common Commands

Source: Internet
Author: User

Backup on CentOS, often packaged with tar, backup to remote directory can use rsync or mount map remote directory, delete expired backup can use FIND,RM, automatic execution can use SH script and crontab mate.

To remind you that all scripts are edited under CentOS, do not upload after editing in Windows, easy to format problems, not normal execution.


Now has a CentOS 7 server, need to back up the directory,/var/backup. Backup to SMB share as an example description


Install SMB share support first, or mount will go wrong

Yum Install Cifs-utils

Using mount to map the SMB share of a remote windowns domain environment to a local directory

Building a mapping Directory

Mkdir/home/backup

Mapping Remote Directories

Mount-t cifs-o username= "username", domain= "domain name", password= "password"//remote server/directory/home/backup


Test backup command

Go to the parent directory where you want to back up the directory

Cd/var

Use tar to package the directory to be backed up to the map directory, tar format, tar-parameter/backup file to store the address/backup directory.

The tar parameter, J uses bzip2 compression, p preserves the file attributes, C creates a new archive, V displays the process, and is scripted when removed.

The backup file name increases the time-to-date parameter, $ (date +%y-%m-%d-%h%m%s).

tar-jpcf/home/backup/backup.$ (date +%y-%m-%d-%h%m%s). tar.bz2 Backup

Automatically delete backup files seven days ago, find/path-type f-mtime +7-exec rm-f {} \;

-type f is the specified file type for normal files,-mtime +7 refers to a file that precedes 7 days, #-exec rm-f refers to a file that performs a silent delete match.

Find/home/backup-type f-mtime +7-exec rm-f {} \;



If all tests are successful, we can start writing backup scripts and remember to change the script to an executable file

#!/bin/bashmount-t cifs-o username= "username", domain= "domain name", password= "password"//remote server/directory Cd/var TAR-JPCF/HOME/BACKUP/MRCRM. $ (date +%y-%m-%d-%h%m%s). tar.bz2 mrcrmcd/home/backup find/home/backup-type f-mtime +7-exec rm-f {} \;unmount/hom E/backup

The script test was successful, and we could use the Auto Execute command to let the script execute automatically at the specified time.

Crontab-l View List-e edit


Reference article:

http://linux.vbird.org/linux_basic/0610hardware.php

We recommend the 20th chapter, the base system and the strategy of the bird brother. The description is more detailed and clear.

This article is from the "focus on drilling 100 years" blog, please be sure to keep this source http://titandeng.blog.51cto.com/823817/1883737

Centos Backup Common Commands

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.