*backup.sh - бэкап файлов и базы mySQL

Резервная копия базы данных отправляется на почту

# 0. VARIABLES
 
EMAIL="backup@tuduf.ru"
DATE=`date +%Y%m%d-%H%M%S-%Z`
 
# 1. BACKUP PROCEDURE FOR FILES
 
tar zcf backup/tuduf.ru-$DATE.tar.gz tuduf.ru/
 
# 2. BACKUP PRODECURE FOR MYSQL DATABASE
 
HOSTNAME=имя_сервера_mysql
DBNAME=имя_базы
DBPASS=мой_пароль
DBUSER=имя_пользователя
 
mysqldump --opt -h $HOSTNAME -u $DBUSER -p$DBPASS $DBNAME > backup.sql
gzip backup.sql
mv backup.sql.gz $HOSTNAME-$DBNAME-$DATE.sql.gz
echo "Backup of $DBNAME @ $HOSTNAME from $DATE is attached" | mutt -a $HOSTNAME-$DBNAME-$DATE.sql.gz $EMAIL -s "MySQL Backup of $DBNAME @ $HOSTNAME"
mv $HOSTNAME-$DBNAME-$DATE.sql.gz backup/
 
# DONE!

*Backup .dotfiles script

#!/usr/bin/env bash
# Backup .dotfiles script.
 
# What to backup. 
backup_files="~/.config"
 
# Where to backup to.
dest="/mnt/data/backup"
mkdir $dest/$(date +"%m_%d_%Y")
 
# Create archive filename.
hostname=$(hostname -s)
archive_file="$hostname-$(date +"%m_%d_%Y").tgz"
 
LOGDIR=/mnt/data/backup/$(date +"%m_%d_%Y")
LOG=${LOGDIR}/backup-$(date +"%m_%d_%Y").log 
ERRLOG=${LOGDIR}/backup-$(date +"%m_%d_%Y").error.log
 
# Print start status message.
echo "Backing up $backup_files to $dest/$dest/$(date +"%m_%d_%Y")/$archive_file"
date
echo
 
# Backup the files using tar.
find . -maxdepth 1 -name ".config" -exec tar -czvf $dest/$(date +"%m_%d_%Y")/$archive_file $backup_files {} + > $LOG 2> $ERRLOG
 
# Print end status message.
echo
echo "Backup finished"
date
 
# Long listing of files in $dest to check file sizes.
ls -lh $dest/$(date +"%m_%d_%Y")
knowledge_base/linux/scripts/backup.sh.txt · Последнее изменение: 2023/02/28 05:09 — tuduf
© 2023 knowledge base by tuduf.ru