-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackupMachine
More file actions
98 lines (65 loc) · 4 KB
/
BackupMachine
File metadata and controls
98 lines (65 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
# author: Krzysztof Palikowski, https://palikowski.net
# this script was created because wordpress backup plugins are cancer :)
# you need to change user and paths to your enviroment obviously
# this is work in progress - i am learning bash :)
# script works in 3 steps:
# 1) connect to several remote servers and pull wordpress files (but tar.gz first on remote machine)
# 2) connect to several remote servers and pull sql dumps files (but those dumps must be prepared on those remote machines first)
# 3) push all to Amazon S3 using rclone (but this can be any cloud storage rclone can connect to)
# i will change all paths and variables to EN lang later :)
# this script runs every 2 days on my cheap VPS from (afiiliate link) https://mikr.us/?r=e6a6d054
# you need to create paswordless RSA key and distribute it to each server you connect to in order to use this script in cron
# i will create a tutorial about this and put a link to it here soon
# please comment or makepull req if you see a better way to do anything, i am not an expert in bash/linux etc.
# remove old log
rm /home/root/scripts/backupLog
# function that gets 2 parameters and then pulls whole directories from remote servers
function createCopy () {
# todayIs = today date in 2021-05-24 format
todayIs=$(date +"%Y-%m-%d")
# create directory for today's backups
mkdir /storage/backupy/fileBackups-"$todayIs"
# nowIs = now, like date+hh+mm+ss
nowIs=$(date +"%Y-%m-%d-%R:%S")
# add timestamp to log
echo "$nowIs zaczalem $2" >> /home/root/scripts/backupLog
ssh -i ~/.ssh/yourRSApaswordlesskey -p $portssh $serwer "tar -czf - $1" > /storage/backupy/fileBackups-"$todayIs"/"$todayIs"-"$2".tar.gz
nowIs=$(date +"%Y-%m-%d-%R:%S")
echo "$nowIs skonczylem $2" >> /home/root/scripts/backupLog
}
# phase 1 - pulling tar.gz directories from remote servers
# firstServer
serwer=login@firstServer.hostname.pl
portssh=22
createCopy "/home/login/domains/1stWordpressDirectoryName/public_html/" "1stPageName"
createCopy "/home/login/domains/2ndWordpressDirectoryName/public_html/" "2ndPageName"
createCopy "/home/login/domains/3rdWordpressDirectoryName/public_html/" "3rdpageName"
# secondServer
portssh=59184
serwer=login@secondServer.hostname.pl
createCopy "/home/login/domains/4thWordpressDirectoryName/public_html" "4thPageName"
# ThirdServer
portssh=22
serwer=login@ThirdServer.hostname.pl
createCopy "/home/login/ftp/5thPageName" "5thPageName"
createCopy "/home/login/ftp/6thPageName" "6thPageName"
# and so on...
# phase 2 - pulling Mysql Dumps from remote servers
mkdir /storage/backupy/sqlDumps-firstServer-"$todayIs"
scp -i ~/.ssh/yourRSApaswordlesskey -r yourLogin@firstServer.hostname.pl:sqlDumps /storage/backupy/sqlDumps-firstServer-"$todayIs"/
mkdir /storage/backupy/sqlDumps-secondServer-"$todayIs"
scp -i ~/.ssh/yourRSApaswordlesskey -P 59184 -r propablyYourLogin@secondServer.hostname.pl:sqlDumps /storage/backupy/sqlDumps-secondServer-"$todayIs"/
# and so on...
# phase 3 - push All to Amazon S3 bucket
todayIs=$(date +"%Y-%m-%d")
nowIs=$(date +"%Y-%m-%d-%R:%S")
echo "$nowIs pushing files to Amazon S3" >> /home/root/scripts/backupLog
# rclone settings for very cheap VPS with 768MB RAM so you need to tweak those
rclone copy /storage/backupy/fileBackups-"$todayIs" s3:yourS3BucketName/cron/"$todayIs"/ --checkers 1 --transfers 1 --use-mmap --buffer-size=64M --tpslimit 3 --s3-chunk-size=64M -q
nowIs=$(date +"%Y-%m-%d-%R:%S")
echo "$nowIs pushing SQL databases to Amazon S3" >> /home/root/scripts/backupLog
rclone copy /storage/backupy/sqlDumps-firstServer-"$todayIs"/kopiebaz s3:yourS3BucketName/cron/"$todayIs"/firstServer --checkers 1 --transfers 1 --use-mmap --buffer-size=64M --tpslimit 3 --s3-chunk-size=64M -q
rclone copy /storage/backupy/sqlDumps-secondServer-"$todayIs"/kopiebaz s3:yourS3BucketName/cron/"$todayIs"/secondServer --checkers 1 --transfers 1 --use-mmap --buffer-size=64M --tpslimit 3 --s3-chunk-size=64M -q
# send mail with backupLog
cat /home/root/scripts/backupLog | pusher log_backupu_stron