Files
VPS-scripts_Ubuntu-Backup/GiteaBackup.sh
2020-02-13 10:36:12 +01:00

58 lines
1.7 KiB
Bash

#################################
#
#Make sure lftp is installed
#if lftp has problem connecting try adding the folowing to /etc/lftp.conf
# set ssl:verify-certificate no
# set ftp:ssl-allow false
#
##################################
## Automation
## add to /etc/crontab and restart cron (/etc/init.d/cron restart)
#30 4 * * * root /bin/sh /root/GiteaBackup.sh
##################################
##Configuration
RMDAYS=14 #Days until first backup gets removed
FTPSERVER=<RemoteServer> #Addres of FTP Server
FTPUSER=<RemoteUser> #User for FTP Server
DBNAME=<DBName> #Database that will be backed up
DBPASS=<DBPassword>
BACKUPFROM="/etc/nginx/ /opt/ /etc/gitea/ /home/git/ /root/ /var/www /etc/lftp.conf /etc/crontab /home/nimda /usr/share/cockpit /etc/ssh /etc/pam.d/cockpit" #Folders and files that will be backed
SITENAME=<SiteName> #Name of site that will be backed up
##Setting Static Variables
LFTP=/usr/bin/lftp # Path to binary
TMPDIR=$(mktemp -d) # Your archives are here
TODAY=$(date --iso) # Today's date like YYYY-MM-DD
RMDATE=$(date --iso -d "$RMDAYS days ago") # TODAY minus X days - too old files
##Run
cd $TMPDIR
#mysqldump -u root -p$ "$DBNAME" > "$TMPDIR"/"$SITENAME".sql #Dumping DB
mysqldump -u root "$DBNAME" --password="$DBPASS" --default-character-set=utf8 > "$TMPDIR"/"$SITENAME".sql #Dumping DB
tar -zcf /"$TMPDIR"/"$SITENAME".tar.gz $BACKUPFROM #Create tar File
#Uploading and remove first backup on FTP
$LFTP << EOF
open -u ${FTPUSER}, sftp://${FTPSERVER}
mkdir -p ${SITENAME}/${TODAY}
cd ${SITENAME}/${TODAY}
mput -E ${TMPDIR}/*
cd ..
rm -rf ${RMDATE}
bye
EOF
rm -r "$TMPDIR" #Deletes Temp Folder