Самый простой backup-скрипт на bash Linux

В этой заметке я покажу пример самого простого бэкап-скрипта на bash Linux.

#!/bin/bash
# This is my backup file - created by 

# here I am setting a time stamp variable which I like to use for logging
TIMESTAMP=`date +%Y%m%d.%H%M`

# here I am setting up the backup directory as a variable
DEST_DIR="/backup/my-backup"

# here I am setting up the directory in which I want to backup, again another variable
SRC_DIR="/home//Documents"

# let's create a variable for the backup file name file
FNAME="MyBackup"

# let's create a variable for the log file, let's also name the log file with the filename and timestamp it
LOG="/home//log/$FNAME-$TIMESTAMP.log"

# start the backup, create a log file which will record any messages run by this script
echo -e "Starting backup of  $SRC_DIR directory" >> ${LOG}

# compress the directory and files, direct the tar.gz file to your destination directory
tar -vczf ${DEST_DIR}/${FNAME}-${TIMESTAMP}.tar.gz ${SRC_DIR} >> ${LOG}

# end the backup, append to log file created by this script
echo -e "Ending backup of  $SRC_DIR" >> ${LOG}

Сохраняем его в удобном для вас каталоге и задаем выполнение по расписанию. Для этого открываем файл /etc/crontab и в конец добавляем строку:

00 00   * * *   root    sh /home/backup/backup1c.sh

Оставить ответ

Ваш e-mail не будет опубликован. Обязательные поля помечены *