From 58e05f63fef5877cced1c57c1264c7cfd7d1d655 Mon Sep 17 00:00:00 2001
From: Alan Hohn <Alan.M.Hohn@lmco.com>
Date: Sat, 28 Mar 2015 18:27:38 -0400
Subject: [PATCH] add user backup / restore for Vagrant

---
 scripts/vagrant/backup.bat     | 3 +++
 scripts/vagrant/backup.sh      | 3 +++
 scripts/vagrant/backupMongo.sh | 8 ++++++++
 scripts/vagrant/fillMongo.sh   | 7 ++++++-
 scripts/vagrant/update.bat     | 3 +++
 scripts/vagrant/update.sh      | 3 +++
 6 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 scripts/vagrant/backup.bat
 create mode 100755 scripts/vagrant/backup.sh
 create mode 100755 scripts/vagrant/backupMongo.sh
 mode change 100644 => 100755 scripts/vagrant/fillMongo.sh
 create mode 100644 scripts/vagrant/update.bat
 create mode 100755 scripts/vagrant/update.sh

diff --git a/scripts/vagrant/backup.bat b/scripts/vagrant/backup.bat
new file mode 100644
index 000000000..430ce5a09
--- /dev/null
+++ b/scripts/vagrant/backup.bat
@@ -0,0 +1,3 @@
+@ECHO OFF
+vagrant ssh -c "cd /vagrant/scripts/vagrant && bash backupMongo.sh"
+
diff --git a/scripts/vagrant/backup.sh b/scripts/vagrant/backup.sh
new file mode 100755
index 000000000..ca91f65a3
--- /dev/null
+++ b/scripts/vagrant/backup.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+vagrant ssh -c "cd /vagrant/scripts/vagrant && bash backupMongo.sh"
+
diff --git a/scripts/vagrant/backupMongo.sh b/scripts/vagrant/backupMongo.sh
new file mode 100755
index 000000000..c7800ae7f
--- /dev/null
+++ b/scripts/vagrant/backupMongo.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+mkdir -p /vagrant/temp
+cd /vagrant/temp
+rm -fr backup
+mkdir backup
+cd backup
+mongodump -db coco --collection users 
+mongodump -db coco --collection earnedachievements
diff --git a/scripts/vagrant/fillMongo.sh b/scripts/vagrant/fillMongo.sh
old mode 100644
new mode 100755
index 477051129..feb401064
--- a/scripts/vagrant/fillMongo.sh
+++ b/scripts/vagrant/fillMongo.sh
@@ -6,4 +6,9 @@ rm -f dump.tar.gz
 rm -rf dump
 wget http://analytics.codecombat.com:8080/dump.tar.gz
 tar xzvf dump.tar.gz --no-same-owner
-mongorestore
+mongorestore --drop
+if [ -d /vagrant/temp/backup ]
+then
+  cd /vagrant/temp/backup
+  mongorestore
+fi
diff --git a/scripts/vagrant/update.bat b/scripts/vagrant/update.bat
new file mode 100644
index 000000000..cc1c3d944
--- /dev/null
+++ b/scripts/vagrant/update.bat
@@ -0,0 +1,3 @@
+@ECHO OFF
+vagrant ssh -c "cd /vagrant/scripts/vagrant && bash fillMongo.sh"
+
diff --git a/scripts/vagrant/update.sh b/scripts/vagrant/update.sh
new file mode 100755
index 000000000..02eadbca4
--- /dev/null
+++ b/scripts/vagrant/update.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+vagrant ssh -c "cd /vagrant/scripts/vagrant && bash fillMongo.sh"
+