Linux 纯shell备份文件
-
克隆项目并进入项目目录:
git clone https://github.91chi.fun/https://github.com/Pricetx/backup.git;cd backup
-
创建所需目录:
mkdir -p /root/backups/temp/
-
添加脚本可执行权限:
chmod +x backup.sh
-
编辑配置文件
backup.cfg
,注释写的很清楚,要配置的也不多,注意:最好给该配置文件配置权限为044
,因为里面存放了加密密码### BACKUP CONFIGURATION ### # KEEP THE PASSWORD SAFE. It is HIGHLY recommended to chmod 400 this file so # that other users can not read it # To decrypt backups made by this script, run the following command: # openssl enc -aes256 -in [encrypted backup] -out decrypted_backup.tgz -pass pass:[backup password] -d -md sha1 #解密命令:openssl enc -aes256 -in 加密文件名.tgz.enc -out decrypted_backup.tgz -pass pass:解密密码 -d -md sha1 ## Edit the entries below to match your needs ## # The password used to encrypt the backup # NOTE: MAKE SURE THAT YOU CHMOD THIS FILE TO 400 TO AVOID UNAUTHORISED ACCESS BACKUPPASS="mysecurepassword" # Directory to store backups #存放本机本分文件路径 LOCALDIR="/root/backups/" # Temporary directory used during backup creation TEMPDIR="/root/backups/temp/" # File to log the outcome of backups LOGFILE="/root/backups/backup.log" # Number of days to store daily local backups LOCALAGEDAILIES="7" # Number of days to store daily remote backups REMOTEAGEDAILIES="7" # Number of days to store weekly local backups LOCALAGEWEEKLIES="28" # Number of days to store weekly remote backups REMOTEAGEWEEKLIES="28" # Number of days to store monthly local backups LOCALAGEMONTHLIES="183" # Number of days to store monthly remote backups REMOTEAGEMONTHLIES="183" # IP / hostname of the server to store remote backups #远程主机IP,即你要把备份文件传到哪台服务器上 REMOTESERVER="REMOTE_SERVER_HERE" # SSH port of remote server REMOTEPORT=22 # User to use with SSH (public key needs to be installed on the remote server) #远程主机用户名(该配置文件中没有配置密码,是因为通过公钥连接的,可以使用ssh-copy-id 用户名@主机名,将公钥放在远程主机上) REMOTEUSER="REMOTE_USER_HERE" # Path to store the remote backups #远程主机存放备份文件路径,注意要保证路径存在,且权限正确 REMOTEDIR="/BACKUP/PATH/ON/REMOTE/SYSTEM/" # Limit bandwidth used by SCP, in Kbit/s. Set to 0 for unlimited. SCPLIMIT=0 # OPTIONAL: If you want MySQL to be backed up, enter the root password below #如果要备份数据库的话,填写mysql数据库密码 ROOTMYSQL="" # Below is a list of files and directories that will be backed up in the tar # backup. To add an entry, add a new line with the same format #需要备份的文件路径 BACKUP+=("/root/backup.cfg") BACKUP+=("/etc/") # Files and directories to exclude from tar backups # To add an entry, add a new line with the same format # NOTE: DO NOT LEAVE A TRAILING SLASH ON LINUX - IT WILL CAUSE IT TO NOT WORK #需要排除的文件路径 EXCLUDE+=("") # Below is a list of files and directories that will be backed up in the rsync # backup. To add an entry, add a new line with the same format # NOTE: DO NOT LEAVE A TRAILING SLASH - IT WILL CAUSE IT TO NOT WORK RSYNCDIR+=("")