diff --git a/applyProdDatabaseToDev.sh b/applyProdDatabaseToDev.sh new file mode 100755 index 0000000..fd9b6ca --- /dev/null +++ b/applyProdDatabaseToDev.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +echo '-------' +echo 'Starting Database Restore' +echo '-------' + +#get Latest database backup + +# Unzip File +# gzip -dk file.gz + +BACKUPDIR="/home/mab/databaseBackupSolidScribe" +DEVDBPASS="Crama!Lama*Jamma###88383!!!!!345345956245i" + +cd $BACKUPDIR + +# -t sort by modification time, newest first +# -A --almost-all, do not list implied . and .. +LASTZIPPEDFILE=$(ls -At *.gz | head -n1) + +# -k keep file after unzip +# -d Decompress +# -v verbose +echo "Unzipping $LASTZIPPEDFILE" +gunzip -dkv $LASTZIPPEDFILE + +BACKUPFILE=$(ls -At *.sql | head -n1) + +#Fix to replace incompatible DB type +echo "Updating table name in $BACKUPFILE" +sed -i $BACKUPFILE -e 's/utf8mb4_0900_ai_ci/utf8mb4_unicode_ci/g' + +echo "Removing and syncing static files" +rm -r /home/mab/ss/staticFiles/* +rsync -e 'ssh -p 13328' -hazC --update mab@solidscribe.com:/home/mab/pi/staticFiles /home/mab/ss/ + +echo "Updating Database" +mysql -u root --password="$DEVDBPASS" < $BACKUPFILE +rm *.sql + +echo '-------' +echo "Applied Prod database to Dev. LastFile: $BACKUPFILE" +echo '-------' \ No newline at end of file diff --git a/backupDatabase.sh b/backupDatabase.sh index 7f521e2..9c67070 100755 --- a/backupDatabase.sh +++ b/backupDatabase.sh @@ -1,18 +1,28 @@ #!/bin/bash -BACKUPDIR="/home/mab/databaseBackupPi" +BACKUPDIR="/home/mab/databaseBackupSolidScribe" mkdir -p $BACKUPDIR cd $BACKUPDIR NOW=$(date +"%Y-%m-%d_%H-%M") -ssh mab@solidscribe.com -p 13328 "mysqldump --all-databases --user root -p***REMOVED***" > "backup-$NOW.sql" +ssh mab@solidscribe.com -p 13328 "mysqldump --all-databases --single-transaction --user root -p***REMOVED***" > "backup-$NOW.sql" +gzip "backup-$NOW.sql" cp "backup-$NOW.sql" "/mnt/Windows Data/DatabaseBackups/backup-$NOW.sql" echo "Database Backup Complete on $NOW" -#Restore DB +## +# Restore DB +## + # copy file over, run restore # scp -P 13328 backup-2019-12-04_03-00.sql mab@avidhabit.com:/home/mab # mysql -u root -p < backup-2019-12-04_03-00.sql + +## +# Crontab setup +## + +# 0 2 * * * /bin/bash /home/mab/ss/backupDatabase.sh 1> /home/mab/databaseBackupLog.txt \ No newline at end of file diff --git a/client/src/components/NoteInputPanel.vue b/client/src/components/NoteInputPanel.vue index abeb1d3..7a4d4af 100644 --- a/client/src/components/NoteInputPanel.vue +++ b/client/src/components/NoteInputPanel.vue @@ -954,20 +954,6 @@ console.log('Focus regained with note open.') console.log('Attempting to fix diff text. fix this. Search spleen') return - - axios.post('/api/note/difftext', postData) - .then( ({data}) => { - - //Don't do anything if nothing has changed - if(data == ''){ return } - - if(data.diffs > 0){ - //Update text and last updated time for note - this.setText(data.updatedText) - this.updated = data.updated - } - }) - .catch(error => { this.$bus.$emit('notification', 'Failed to get diff') }) } //Track visibility state diff --git a/server/models/Note.js b/server/models/Note.js index 04d9e8f..9367b3d 100644 --- a/server/models/Note.js +++ b/server/models/Note.js @@ -658,60 +658,6 @@ Note.delete = (userId, noteId, masterKey = null) => { }) } -//text is the current text for the note that will be compared to the text in the database -Note.getDiffText = (userId, noteId, usersCurrentText, lastUpdated) => { - return new Promise((resolve, reject) => { - Note.get(userId, noteId) - .then(noteObject => { - - if(!noteObject.text || !usersCurrentText || noteObject.encrypted == 1){ - return resolve(null) - } - - let oldText = noteObject.text.replace(/(\r\n|\n|\r)/gm,"") - let newText = usersCurrentText.replace(/(\r\n|\n|\r)/gm,"") - - if(noteObject.updated == lastUpdated){ - // console.log('No note diff') - return resolve(null) - } - - if(noteObject.updated > lastUpdated){ - newText = noteObject.text.replace(/(\r\n|\n|\r)/gm,"") - oldText = usersCurrentText.replace(/(\r\n|\n|\r)/gm,"") - } - - const dmp = new DiffMatchPatch.diff_match_patch() - const diff = dmp.diff_main(oldText, newText) - - dmp.diff_cleanupSemantic(diff) - const patch_list = dmp.patch_make(oldText, newText, diff); - const patch_text = dmp.patch_toText(patch_list); - - //Patch text - shows a list of changes - var patches = dmp.patch_fromText(patch_text); - // console.log(patch_text) - - //results[1] - contains diagnostic data for patch apply, its possible it can fail - var results = dmp.patch_apply(patches, oldText); - - //Compile return data for front end - const returnData = { - updatedText: results[0], - diffs: results[1].length, //Only use length for now - updated: Math.max(noteObject.updated,lastUpdated) //Return most recently updated date - - } - - //Final change in notes - // console.log(returnData) - - resolve(returnData) - }) - }) - -} - Note.get = (userId, noteId, masterKey) => { return new Promise((resolve, reject) => { diff --git a/server/routes/noteController.js b/server/routes/noteController.js index 2ee7f20..2c59a05 100644 --- a/server/routes/noteController.js +++ b/server/routes/noteController.js @@ -60,14 +60,6 @@ router.post('/search', function (req, res) { }) }) -router.post('/difftext', function (req, res) { - Note.getDiffText(userId, req.body.noteId, req.body.text, req.body.updated) - .then( fullDiffText => { - //Response should be full diff text - res.send(fullDiffText) - }) -}) - router.post('/reindex', function (req, res) { Note.reindex(userId, masterKey) .then( data => { diff --git a/startDevServerAndClient.sh b/startDevServerAndClient.sh index 52bef99..8b81953 100755 --- a/startDevServerAndClient.sh +++ b/startDevServerAndClient.sh @@ -1,10 +1,10 @@ #!/bin/bash -echo 'Make sure this is being run from root folder of project' +cd /home/mab/ss -echo 'Starting Client webpack dev server (/app), in a screen, watching for file changes...' -screen -dm bash -c "cd client/; npm run watch" +echo '::--:: Starting dev server. cd client; npm run serve -> 192.168.1.164:8081' +screen -dmS "NoteClientScreen" bash -c "cd /home/mab/ss/client; npm run serve" -echo 'Starting API server (/api), watching for file changes...' -cd server -pm2 start ecosystem.config.js +echo '::--:: Starting API server (/api), watching for file changes...' +cd /home/mab/ss/server +pm2 start ecosystem.config.js \ No newline at end of file