forked from jlark/azurelinuxbackup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackupAzure
executable file
·56 lines (43 loc) · 1.47 KB
/
backupAzure
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
#!/bin/bash
# full system backup
# Backup destination
backdest=/opt/backup
# Labels for backup name
pc=${HOSTNAME}
distro=`uname -a | awk '{print $4}'`
type=full
date=$(date "+%F")
backupfile="$backdest/$distro-$type-$date.tar.gz"
username=`whoami`
#blob storage variables
storageAccountName=<YOUR AZURE STORAGE ACCOUNT NAME>
storageAccountKey=<YOUR AZURE STORAGE KEY>
storageContainer=<YOUR AZURE CONTAINER NAME>
# Exclude file location
prog=${0##*/} # Program name from filename
excdir=`pwd`
exclude_file="$excdir/$prog-exc.txt"
azure_account_file=="/home/$username/azure_account.xml"
#check backup destination is there
if [ ! -d "$backdest" ]; then
mkdir -p $backdest
fi
# Check if exclude file exists
if [ ! -f $exclude_file ]; then
echo "checking exclude $exclude_file"
echo -n "No exclude file exists, continue? (y/n): "
read continue
if [ $continue == "n" ]; then exit; fi
fi
#if [ ! -f $azure_account_file ]; then
# echo "azure user accout doesn't exist cannot connect to blob storage without it $azure_account_file"
# echo "run > azure accout download"
# echo -n "do you wish to continue? this will only create a local backup (y/n)"
# read continue
# if [ $continue == "n" ]; then exit; fi
#fi
#don't use nohup we want to make this blocking
tar --exclude-from=$exclude_file -czpvf $backupfile /
#after tar is finished move to blob storage
azure storage blob upload -a $storageAccountName --container $storageContainer -k $storageAccountKey $backupfile
echo "all done!"