forked from kuronekomichael/aws-glacier-multipart-upload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplitEncryptParts.sh
executable file
·49 lines (31 loc) · 1.27 KB
/
splitEncryptParts.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
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "USAGE: $0 filename"
exit 1
fi
filename=$1
if [ -z "$chunkSize" ]; then
chunkSize=1024
fi
byteSize=$(expr $chunkSize \* 1024 \* 1024)
#Configura as variaveis usadads
. /opt/gradus/conf/grs-variables
SISTEMA=`cut -d - -f1 /etc/hostname`
CLIENTE=`cut -d - -f2 /etc/hostname`
AMBIENTE=`cut -d - -f3 /etc/hostname`
#Nome do arquivo que vai ser subido
DUMP_FILENAME=${filename}
DUMP_FILENAME_PART="${DUMP_FILENAME}-part-"
FOLDER_TAR="${DUMP_FILENAME}.tar"
FOLDER_TAR_PART="${DUMP_FILENAME}.tar-part-"
CERT1_FILE="${GRS_CONF_CRYPTO_DIR}/gradus-masterkey-publiccert.pem"
CERT2_FILE="${GRS_CONF_CRYPTO_DIR}/${SISTEMA}-backups-${CLIENTE}-${AMBIENTE}-publiccert.pem"
CERT2_FILENAME="$(basename $(readlink -f ${CERT2_FILE}))"
GRS_DATABASE_CONF_FILE="${GRS_CONF_DATABASE_DIR}/database.cnf"
VAULT_NAME=${SISTEMA}-${CLIENTE}-backups-001
#divide em pegados de 1gb****
split -b ${byteSize} ${DUMP_FILENAME} ${DUMP_FILENAME_PART}
# Encrypta o DUMP_FILE's usando as chaves gradus-masterkey e a chave especifica do container****
for f in ${DUMP_FILENAME_PART}* ; do [ -f $f ] && openssl smime -encrypt -stream -aes256 -in $f -binary -outform DEM ${CERT1_FILE} ${CERT2_FILE} > $f.crypt && rm $f ; done
tar -cvf ${FOLDER_TAR} *.crypt
rm *-part-*