📜 ⬆️ ⬇️

Script backup vps servers

In connection with the events at Clodo , I post my script for backup. Very suitable for small vps. Sharpened for Ubuntu, but I think this is not a problem.

The script creates 2 archives: in one file, in another directory with dumps of the entire database in databases .
Need to change the settings at the beginning.

#!/bin/bash USER=root #   PASSWORD=password # BACKUP=/media/Backup #   LOG=/var/log #      OLD=30 #     (   ) PREFIX=work #    -   ,    DATE=`date '+%Y-%m-%d'` echo "Backup database to $BACKUP" mkdir $BACKUP/$DATE.sql cd $BACKUP/$DATE.sql for i in `mysql -u $USER -p$PASSWORD -e'show databases;' | grep -v information_schema | grep -v Database`; do mysqldump -u $USER -p$PASSWORD $i > $DATE-$i.sql; done cd .. tar -cjf $BACKUP/$DATE-sql-$PREFIX.tar.bz2 ./$DATE.sql rm -rf ./$DATE.sql echo "Backup files to $BACKUP" tar -cjf $BACKUP/$DATE-files-$PREFIX.tar.bz2 \ /var/www/ \ /etc/ \ /var/log/ \ /root/ \ --exclude=$BACKUP echo "Deleting old backups and logs from $BACKUP & $LOG" find $LOG -type f \( -name "*.gz" -o -name "*.1*" \) -exec rm '{}' \; find $BACKUP -mtime +$OLD -exec rm '{}' \; 


PS Setting Dropbox on the server.

')

Source: https://habr.com/ru/post/121120/


All Articles