-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from lucascbeyeler/dev
BETA 3 Bugfix and partially new function
- Loading branch information
Showing
14 changed files
with
201 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/bin/bash | ||
################################################################################ | ||
# Database Actions - Sqlite Drive | ||
################################################################################ | ||
|
||
############################################################################### | ||
# create_session: Migrate the entire sessions.txt to SQLite database | ||
############################################################################### | ||
function create_session(){ | ||
if [[ $SESSION_TYPE == 'TXT' ]]; then | ||
touch $WORKDIR/sessions.txt | ||
echo "Session file recreated" | ||
elif [[ $SESSION_TYPE == "SQLITE3" ]]; then | ||
sqlite3 $WORKDIR/sessions.sqlite3 < /usr/local/lib/zmbackup/sqlite3/database.sql | ||
else | ||
echo "Invalid File Format - Nothing to do." | ||
fi | ||
} | ||
|
||
############################################################################### | ||
# importsession: Migrate the sessions from the txt file to the sqlite3 database | ||
############################################################################### | ||
function importsession(){ | ||
for i in $(egrep 'SESSION:' $WORKDIR/sessions.txt | egrep 'started' | awk '{print $2}' | sort | uniq); do | ||
SESSIONID=$i | ||
OPT=$(echo $i | cut -d"-" -f1 ) | ||
case $OPT in | ||
"full") | ||
OPT="Full Backup" | ||
YEAR=$(echo $i | cut -c6-9) | ||
MONTH=$(echo $i | cut -c10-11) | ||
DAY=$(echo $i | cut -c12-13) | ||
;; | ||
"inc") | ||
OPT="Incremental Backup" | ||
YEAR=$(echo $i | cut -c5-8) | ||
MONTH=$(echo $i | cut -c9-10) | ||
DAY=$(echo $i | cut -c11-12) | ||
;; | ||
"distlist") | ||
OPT="Distribution List Backup" | ||
YEAR=$(echo $i | cut -c10-13) | ||
MONTH=$(echo $i | cut -c14-15) | ||
DAY=$(echo $i | cut -c16-17) | ||
;; | ||
"alias") | ||
OPT="Alias Backup" | ||
YEAR=$(echo $i | cut -c7-10) | ||
MONTH=$(echo $i | cut -c11-12) | ||
DAY=$(echo $i | cut -c13-14) | ||
;; | ||
"ldap") | ||
OPT="Account Backup - Only LDAP" | ||
YEAR=$(echo $i | cut -c6-9) | ||
MONTH=$(echo $i | cut -c10-11) | ||
DAY=$(echo $i | cut -c12-13) | ||
;; | ||
esac | ||
INITIAL=$YEAR'-'$MONTH'-'$DAY"T00:00:00.000" | ||
CONCLUSION=$YEAR'-'$MONTH'-'$DAY"T00:00:00.000" | ||
SIZE=$(du -h $WORKDIR/$i | awk {'print $1'}) | ||
STATUS="FINISHED" | ||
sqlite3 $DATABASE "insert into backup_session values ('$SESSIONID','$INITIAL','$CONCLUSION','$SIZE','$OPT','$STATUS')" | ||
done | ||
} | ||
|
||
############################################################################### | ||
# importaccounts: Migrate the accounts from the txt file to the sqlite3 database | ||
############################################################################### | ||
function importaccounts(){ | ||
for i in $(egrep 'SESSION:' $WORKDIR/sessions.txt | egrep 'started' | awk '{print $2}' | sort | uniq); do | ||
SESSIONID=$i | ||
for j in $(egrep $i $WORKDIR/sessions.txt | grep -v 'SESSION:' | sort | uniq); do | ||
EMAIL=$(echo $j | cut -d":" -f2) | ||
SIZE=$(du -h $WORKDIR/$i/$EMAIL.tgz | awk {'print $1'}) | ||
sqlite3 $DATABASE "insert into backup_account (email) values ('$EMAIL')" > /dev/null | ||
ID=$(sqlite3 $DATABASE "select accountID from backup_account where email='$EMAIL'") | ||
sqlite3 $DATABASE "insert into session_account (accountID,sessionID,account_size) values ('$ID','$SESSIONID','$SIZE')" > /dev/null | ||
done | ||
done | ||
} | ||
|
||
############################################################################### | ||
# migration: Execute migration action | ||
############################################################################### | ||
function migration(){ | ||
if [[ $SESSION_TYPE == "SQLITE3" ]] && ! [[ -f $WORKDIR/sessions.sqlite3 ]]; then | ||
echo "Starting the migration - please wait until the conclusion" | ||
create_session | ||
importsession | ||
importaccounts | ||
echo "Migration completed" | ||
rm $WORKDIR/sessions.txt | ||
elif [[ $SESSION_TYPE == "TXT" ]] && ! [[ -f $WORKDIR/sessions.txt ]]; then | ||
create_session | ||
rm $WORKDIR/sessions.sqlite3 | ||
else | ||
echo "Nothing to do." | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
create table backup_session( | ||
sessionID varchar primary key, | ||
initial_date timestamp not null, | ||
conclusion_date timestamp not null, | ||
size varchar not null, | ||
type varchar not null, | ||
status varchar not null | ||
); | ||
|
||
create table backup_account( | ||
accountID integer primary key autoincrement unique, | ||
email varchar not null); | ||
|
||
create table session_account( | ||
id integer primary key autoincrement, | ||
accountID int not null, | ||
sessionID varchar not null, | ||
account_size varchar not null, | ||
foreign key (accountID) references backup_account(accountID), | ||
foreign key (sessionID) references backup_session(sessionID) | ||
); | ||
|
||
create table backup_queue( | ||
id integer primary key autoincrement, | ||
accountID int not null, | ||
sessionID varchar not null, | ||
foreign key (accountID) references backup_account(accountID), | ||
foreign key (sessionID) references backup_session(sessionID) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters