(Grav GitSync) Automatic Commit from tanshu

This commit is contained in:
tanshu 2018-08-07 14:54:38 +00:00 committed by GitSync
parent 31b3f5ceb7
commit 51869c3ba9

View File

@ -1,75 +1,22 @@
--- ---
title: 'mikrotik Backup 2' title: 'pfSense Backup'
--- ---
#### 1. Script for DDNS #### 1. Script for DDNS
Create the following script with name `TanBack` and the following permissions `ftp,read,write,policy,test,sensitive` Create the following script with name `/root/backup.sh` and make it executable with `chmod +x /root/backup.sh`. Replace the ? in the last scp command with the right IP Address
``` ```
# Tanshu automatic DNS updates #!/bin/sh
:local date [/system clock get date]; DATE=`date +%Y.%m.%d`
:local day [:pick $date 4 6]; scp /cf/conf/config.xml "tanshu@hopsngrains.com:Data/10.?.0.x/pfsense-10.?.0.1-$DATE.xml"
:local month [:pick $date 0 3];
:if ([$month] = "jan") do={ :set month 01 };
:if ([$month] = "feb") do={ :set month 02 };
:if ([$month] = "mar") do={ :set month 03 };
:if ([$month] = "apr") do={ :set month 04 };
:if ([$month] = "may") do={ :set month 05 };
:if ([$month] = "jun") do={ :set month 06 };
:if ([$month] = "jul") do={ :set month 07 };
:if ([$month] = "aug") do={ :set month 08 };
:if ([$month] = "sep") do={ :set month 09 };
:if ([$month] = "oct") do={ :set month 10 };
:if ([$month] = "nov") do={ :set month 11 };
:if ([$month] = "dec") do={ :set month 12 };
:local year [:pick $date 7 11];
:local time [:pick [/system clock get time] 0 5];
:local filename ("Data/mikrotik-Home/mikrotik_$year-$month-$day-$time.rsc");
/export file=export.rsc;
/tool fetch address=hopsngrains.com src-path=export.rsc user=tanshu mode=ftp password=tan12shu dst-path=($filen>
:log info "TanBack: Backup uploaded with filename $filename"
``` ```
#### 2. Schedule the script #### 2. Schedule the script
Create the following schedule with name `TanBack-Daily` and the following permissions `ftp,read,write,policy,test,sensitive`, `1 day` interval and `TanBack` On Event. Edit crontab using `crontab -e`. Swith to insert mode by pressing `i`. Paste the following command `0 13 * * * /root/backup.sh`. Go back to command mode with `esc`. Save using `:wq`
#### 3. Server preperation #### 3. Server preperation
```sh ```sh
mkdir -p ~/Data/mikrotik-Home mkdir -p ~/Data/10.?.0.x/
```
#### 4. Install gdrive
Install gdrive to backup the database to google account in case of data loss at webfaction
Go to `https://github.com/prasmussen/gdrive` and download `gdrive-linux-x64` in `~/bin/`
```sh
wget -o ~/bin/gdrive $URL_FOR_GDRIVE_LINUX_X64_BINARY
```
Make it executable `chmod +x ~/bin/gdrive`
#### 5. Configure Google Drive
Link your gdrive to the account by running `gdrive list` and following the instructions.
Create a folder called `mikrotik-Home` and get its id by running `gdrive list`.
Create upload script named `mk.sh` in the home directory and make it executable `chmod +x ~/mk.sh`
```sh
#!/usr/bin/env bash
for filename in ~/Data/mikrotik-Home/*.rsc; do
hash=`sha512sum ${filename} | awk '{ print $1 }'`
if grep -q "$hash" ~/Data/mikrotik-Home/mikrotik.sha512sums; then
echo "File $(basename $filename) is uploaded"
else
echo "Need to upload $filename"
sha512sum "$filename" >> ~/Data/mikrotik-Home/mikrotik.sha512sums
~/bin/gdrive upload --parent 1eO7hJ6b8_4n43B8GWSVyBtoon4vZyhs6 "$filename"
fi
done```
#### 6. Automate Backups
Edit crontab using `export VISUAL=nano; crontab -e` and add the following line
```sh
0 1 * * * ~/mk.sh
``` ```