-
Notifications
You must be signed in to change notification settings - Fork 2
/
dashninja-dbdump.sh
executable file
·62 lines (47 loc) · 1.54 KB
/
dashninja-dbdump.sh
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
#!/bin/bash
DB_user=dmndbdump
DB=dashninja_prod
MAINDIR=./dump
DIR=dashninja-dbdump-$(date +%Y%m%d%H%M%S)
DUMPDIR=$MAINDIR/$DIR
DUMPNAM=$DIR.txz
FULLDUMPNAM=$MAINDIR/$DUMPNAM
TIMESTAMP=$(date +%s)
DATE=$(date -u)
LINKSFILE=$(head -n 13 links.md)
HEADER=$(cat header.md)
[ -n "$DUMPDIR" ] || DUMPDIR=.
test -d $DUMPDIR || mkdir -p $DUMPDIR
echo "Dumping tables into separate SQL command files for database '$DB' into dir=$DUMPDIR"
tbl_count=0
for t in $(mysql -NBA -u $DB_user -D $DB -e 'show tables')
do
echo "DUMPING TABLE: $DB.$t"
mysqldump -u $DB_user --lock-tables=false $DB $t > $DUMPDIR/$t.sql
tbl_count=$(( tbl_count + 1 ))
done
echo "$tbl_count tables dumped from database '$DB' into dir=$DUMPDIR"
echo "Compressing archive $DUMPNAM into $DUMPDIR"
cd $MAINDIR
tar cvJf $DUMPNAM $DIR
cd ..
echo "Calculating checksum of $DIRFIN/$DUMPNAM"
SIZE=$(stat -c%s $FULLDUMPNAM)
#SHA1=$(sha1sum $FULLDUMPNAM | cut -f1 -d' ')
SHA256=$(sha256sum $FULLDUMPNAM | cut -f1 -d' ')
echo "Sending $DIRFIN/$DUMPNAM to oshi.at"
URLS=$(curl --progress-bar -T $FULLDUMPNAM https://oshi.at/$DUMPNAM/21600)
URL=$(echo "$URLS" | head -3 | tail -1 | cut -d" " -f1)
ONIONURL=$(echo "$URLS" | head -5 | tail -1 | cut -d" " -f1)
echo "Cleaning up"
rm $FULLDUMPNAM
cd $MAINDIR
rm -rf $DIR
cd ..
echo "Generating new links.md file and README.md"
echo -e "| $DATE | [Direct]($URL) [Onion]($ONIONURL) | $SIZE | $SHA256 | \n$LINKSFILE" > links.md
cat header.md links.md > README.md
echo "Auto commit and push"
git add README.md links.md
git commit -m "$DATE - autoupdate"
git push