#! /bin/bash # Script to backup files by compressing them local and transfer to a ftp server # Don't copy this script in the $BACKUPPATH, it will be deleted at the end of this script # to run this script by a crontab on mondays at 6am type "crontab -e" and add the line "* 6 * * 1 /root/Scripts/ftp_backup.sh" # If you change the file path and / or name of this script, change your crontab entry # Give execute rights by "chmod u+x ftp_backup.sh" # This script is intended to be uses as root, so you can stop services bevor you backup # Author: HelgeKoenig@GMX.de - http://HelgeKoenig.de # Parameters not to change DATE_VAR=$(date +"%Y%m%d") #Parameters to change BACKUPPATH="/root/backup/" #path to the local backup folder SQL_USER="root" #SQL root user for DB Backup SQL_PW="password123" #see SQL_USER FTP_IP="sftp.hidrive.strato.com" #IP or Adress for the backup ftp server FTP_USER="hidriveusername" #Should be self-explaining FTP_PATH="/users/hidriveusername/" #Remote FTP Path where the files should go #check for $BACKUP folder and if fails creating if [ ! -d $BACKUPPATH ]; then mkdir $BACKUPPATH; fi #Let teh backup beginz! if [ `whoami` = root ] #check for root user then { #create compressed backups tar cvz -f $BACKUPPATH/etc_$DATE_VAR.tgz /etc/ #MySQL Database Eport. Change DB_NAME to your actual Databasename you want to backup mysqldump --user=$SQL_USER --password=$SQL_PW --databases "DB_NAME" > "$BACKUPPATH/DB_NAME_$DATE_VAR.sql" gzip "$BACKUPPATH/DB_NAME_$DATE_VAR.sql" #SFTP Upload to HiDrive sftp $FTP_USER@$FTP_IP -b <