11#! /bin/bash
22# ##################################
33#
4- # Automated server backups
4+ # Backup to NFS mount script.
55#
66# ##################################
77
8+ # give your script a name
9+ host=hostname
10+
811# what to backup
9- # backup folders
10- backup_files=" /var/www/my-website.de /var/www/wordpress /etc"
12+ backup_files= " /var/www/wordpress /var/www/mywebsite "
13+ # backup_files="/home/deploy/repositories /etc"
1114
12- # backup databases
13- backup_databases=" mywebsite wordpress"
15+ # which databases
16+ backup_databases=" wordpress mywebsite "
1417
1518# where to backup
1619dest=" /mnt/backup"
@@ -20,44 +23,68 @@ mkdir -p $dest
2023
2124# create archive filenames
2225day=$( date +%y-%m-%d)
23- hostname=$( hostname -s)
24- archive_file=" $hostname -$day .tar"
25- mysql_file=" $hostname -mysql-$day .tar"
26+ archive_file=" $host -$day .tar"
27+ mysql_file=" $host -mysql-$day .tar"
2628
2729# print start status message
28- echo " Backing up $backup_files to $dest /$archive_file ..."
29- echo " Backing up $backup_databases to $dest /$mysql_file ..."
30- date
31- echo
32- echo " ================================================================"
33- echo
34- echo " Download database backup with $ scp backup@185.102.93.107:backups/$mysql_file backup"
35- echo
30+ echo " Dear $host product owner,"
31+ echo " "
32+ echo " a new backup of your server was generated on your server."
33+ echo " You can find the files and folder under $dest /$archive_file and databases here $dest /$mysql_file . The backup included the follwing data:"
34+ echo " "
35+ echo " Folders: $backup_files "
36+ echo " Databases: $backup_databases "
37+ echo " "
38+ echo " "
39+ echo " "
40+ echo " ==================== DOWNLOAD WITH SCP ======================"
41+ echo " "
42+ echo " SQL database"
43+ echo " Download database backup with $ scp root@111.222.333.444:/backups/$mysql_file backup"
3644echo " Unpack files with $ tar -xvzf backup/$mysql_file "
37- echo
38- echo " Download the full backup with with $ scp backup@185.102.93.107:backups/ $archive_file backup "
39- echo
45+ echo " "
46+ echo " Files and Folders: "
47+ echo " Download the full backup with with $ scp root@111.222.333.444:/backups/ $archive_file backup "
4048echo " Unpack files with $ tar -xvzf backup/$archive_file "
4149echo
42- echo " ======================================== ========================="
50+ echo " ====================== FTP DOWNLOAD ========================="
4351echo " "
52+ echo " Acces with FTP:"
53+ echo " USER: root"
54+ echo " PASS: X"
55+ echo " SERV: 111.222.333.444"
56+ echo " Download with FTP client manually"
57+ echo " "
58+ echo " =============================================================="
59+ echo " "
60+ echo " "
61+ echo " I wish you a nice day !"
62+ echo " "
63+ echo " "
64+ echo " ========================== LOG ==============================="
65+ echo " "
66+ echo " Starting script..."
67+ date
4468
45- # database dump in temp file
69+ # backup the files using tar.
4670tar czvfP $dest /$archive_file $backup_files
4771
48- # pack the sql dump with tar and remove dump
72+ # database backup
4973mysqldump --user root --routines --triggers --single-transaction --databases $backup_databases > " $dest /sql_dump.sql"
50- tar czfP $dest /$mysql_file " $dest /sql_dump.sql"
51- rm $dest /sql_dump.sql
74+ tar czfP $dest /$mysql_file " $dest /sql_dump.sql" && rm $dest /sql_dump.sql
5275
5376# print end status message
54- echo
55- echo " Backup SUCCESS"
77+ echo " ."
78+ echo " ."
79+ echo " ."
80+ echo " ... Backup SUCCESS!"
5681date
57- echo
58- echo " Delete old files"
82+ echo " "
83+ echo " Delete old files !"
84+ find $dest -mtime +14 -type f
5985find $dest -mtime +14 -type f -delete
60- echo
86+ echo " "
6187
62- # echo generated files
88+ # long listing of files in $dest to check file sizes
89+ echo " Files generated"
6390ls -lh $dest
0 commit comments