Index: /branches/amp_3_7/src/webui/webui/htdocs/new/src/cm/lib/postgres_db.py
===================================================================
--- /branches/amp_3_7/src/webui/webui/htdocs/new/src/cm/lib/postgres_db.py	(revision 2496)
+++ /branches/amp_3_7/src/webui/webui/htdocs/new/src/cm/lib/postgres_db.py	(working copy)
@@ -418,10 +418,35 @@
                               time varchar(30) NOT NULL,
                               result varchar(20) NOT NULL
                             );
-                            ALTER TABLE ext_log ADD COLUMN IF NOT EXISTS id BIGSERIAL;
-                            ALTER TABLE ext_log ADD CONSTRAINT ext_log_pkey PRIMARY KEY (id);
                             '''
+        add_column_sql = '''
+        DO $$
+        BEGIN
+            IF NOT EXISTS (
+                SELECT 1 FROM information_schema.columns
+                WHERE table_name='ext_log' AND column_name='id'
+            ) THEN
+                ALTER TABLE ext_log ADD COLUMN id BIGSERIAL;
+            END IF;
+        END
+        $$;
+        '''
+        add_pk_sql = '''
+        DO $$
+        BEGIN
+            IF NOT EXISTS (
+                SELECT 1 FROM information_schema.table_constraints
+                WHERE table_name='ext_log' AND constraint_type='PRIMARY KEY'
+            ) THEN
+                ALTER TABLE ext_log ADD CONSTRAINT ext_log_pkey PRIMARY KEY     (id);
+            END IF;
+        END
+        $$;
+        '''
+
         self.execute_sql(create_table_sql)
+        self.execute_sql(add_column_sql)
+        self.execute_sql(add_pk_sql)
 
     def create_table_user_authorization(self):
         print('Creating table user_authorization...')
@@ -521,6 +546,31 @@
                           '''
         self.execute_sql(create_table_sql)
 
+    def create_table_remote_storage(self):
+        print('Creating table remote_storage...')
+        create_table_sql = ''' 
+        CREATE TABLE IF NOT EXISTS remote_storage (
+            id SERIAL PRIMARY KEY,
+            ip varchar(64) NOT NULL,
+            username  varchar(64) NOT NULL,
+            password varchar(64) NOT NULL,
+            path varchar(64) DEFAULT NULL
+        );
+                          '''
+        self.execute_sql(create_table_sql)
+
+    def create_table_backups(self):
+        print('Creating table backups...')
+        create_table_sql = ''' 
+        CREATE TABLE IF NOT EXISTS backups (
+            id SERIAL PRIMARY KEY,
+            filename varchar(64) NOT NULL,
+            status varchar(64) DEFAULT NULL,
+            time  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
+        );
+                          '''
+        self.execute_sql(create_table_sql)
+
 
 if __name__ == '__main__':
     db = DB.get_connected_db()
@@ -553,4 +603,6 @@
     db.create_table_device_config_template()
     db.create_table_role_device_group()
     db.create_table_backup_schedule()
+    db.create_table_remote_storage()
+    db.create_table_backups()
     db.close()
\ No newline at end of file
Index: /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/controller/backup_controller.py
===================================================================
--- /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/controller/backup_controller.py	(revision 2496)
+++ /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/controller/backup_controller.py	(working copy)
@@ -8,22 +8,39 @@
 from hive.utils import andebug, get_current_session
 from hive.services.service_utils import ServiceUtils
 from hive.services.schedule_backup import schedule_backup_job, fetch_schedule_backup_data, remove_backup_cron_job
+from hive.services.backup_service_utils import persist_remote_storage_details, fetch_remote_storage_details
+from hive.services.backup_service import BackupConfig
 
 BACKUP_SCRIPT_FILE = "/ca/webui/htdocs/new/src/cm/backup/backup.sh"
 BACKUP_LOG_FILE = "/var/log/backup.log"
-BACKUP_DOWNLOAD_FILE = "/var/backups"
+BACKUP_DOWNLOAD_LOC = "/var/backups"
 
 
 def start_backup(request):
     """ Starts the backup in the background."""
     try:
+        data = json.loads(request.body)
+        backup_target = data.get("backup_target")
+        if not backup_target:
+            return HttpResponse(json.dumps({
+                'error': 400,
+                'message': "Back up destination not specified. Please specify value for 'backup_target'"
+            }), content_type='application/json', status=400)
+
+        if not (backup_target == ServiceUtils.LOCAL or backup_target == ServiceUtils.REMOTE):
+            return HttpResponse(json.dumps({
+                'error': 400,
+                'message': "Incorrect value specified for 'backup_target'.",
+                'description': "Please use 'local' or 'remote' value for 'backup_target'"
+            }), content_type='application/json', status=400)
+
         session = get_current_session()
         session.cli.set_enable()
         session.cli.cmd("config terminal")
         output = session.cli.cmd("show run")
         cmd = (
             "import sys; sys.path.append('/ca/webui/htdocs/new/src/hive/services'); from backup_service import "
-            "BackupConfig; BackupConfig().perform_backup()"
+            "BackupConfig; BackupConfig().perform_backup(destination='{}')".format(backup_target)
         )
         # Creating another process so that it runs in background
         p1 = subprocess.Popen(["python", "-c", cmd],
@@ -39,37 +56,6 @@
         raise ge.GenericError(500, e.message)
 
 
-def backup_status(request):
-    """ Fetch the Backup status """
-    try:
-        with open(BACKUP_LOG_FILE, 'r') as backup_file:
-            logs = backup_file.readlines()[-2:]
-    except IOError as e:
-        message = str(e.message).replace("'", "")
-        oper_log('error', 'system', 'No log found!,  details: {}'.format(message))
-        e.message = 'No log found!,  details: {}'.format(message)
-        raise ge.GenericError(204, message)
-
-    try:
-        for line in reversed(logs):
-            if "Backup completed" in line in line:
-                backup_filename = str(line).split("Backup completed:")[1].strip()
-                scheme = "https" if request.is_secure() else "http"
-                download_url = (scheme + "://" + request.get_host() + "/backup/download?filename={}".format(
-                    backup_filename))
-                return HttpResponse(json.dumps({"message": "Backup Completed!",
-                                                "download_url": download_url}), content_type='application/json')
-            elif "failed" in line:
-                return HttpResponse(json.dumps({"message": "Backup Failed!"}), content_type='application/json')
-    except Exception as e:
-        message = str(e).replace("'", "")
-        oper_log('error', 'system', 'Exception while creating backup.,  details: {}'.format(message))
-        e.message = 'Exception while creating backup.,  details: {}'.format(message)
-        raise ge.GenericError(500, e.message)
-
-    return HttpResponse(json.dumps({"message": "Backup in Progress!"}), content_type='application/json')
-
-
 def file_iterator(file_path, chunk_size=8192):
     """ Iterates over the file contents returning a chunk of data each time """
     with open(file_path, 'rb') as file:
@@ -89,7 +75,7 @@
                 "message": "Filename not provided. Please provide the Backup filename"
             }), content_type='application/json', status=400)
 
-        file_path = os.path.join(BACKUP_DOWNLOAD_FILE, filename)
+        file_path = os.path.join(BACKUP_DOWNLOAD_LOC, filename)
 
         if not os.path.exists(file_path):
             return HttpResponse(json.dumps({
@@ -162,13 +148,84 @@
     return fetch_schedule_backup_data()
 
 
+def get_backup_file_list(request):
+    """ Fetches the list of backups in the system """
+    backup_config = BackupConfig()
+    return backup_config.get_backup_files_info()
+
+
+def remove_backup_file(filename):
+    """ Removes the backup file from the system and also from the DB """
+    try:
+        if not filename:
+            return HttpResponse(json.dumps({
+                "error": 400,
+                "message": "Filename not provided. Please provide the Backup filename"
+            }), content_type='application/json', status=400)
+
+        backup_config = BackupConfig()
+        response = backup_config.delete_backup_file(filename)
+        if response:
+            return response
+        else:
+            return HttpResponse(json.dumps({"message": "Successfully deleted backup file: {}".format(filename)}),
+                                content_type='application/json')
+    except IOError as e:
+        message = str(e).replace("'", "")
+        oper_log('error', 'system', 'Error removing backup file from the system!,  details: {}'.format(message))
+        raise ge.GenericError(500, "Error removing backup file from the system!")
+
+
+def save_remote_storage_details(request):
+    """ Handles user request to persist the remote disk details """
+    data = json.loads(request.body)
+    ip = data.get("ip_address")
+    username = data.get("username")
+    passwd = data.get("password")
+    path = data.get("path")
+
+    return persist_remote_storage_details(ip, username, passwd, path)
+
+
+def get_backup_status(request):
+    """ Fetches the list of backups in the system """
+    backup_config = BackupConfig()
+    return backup_config.get_backup_status()
+
+
+def get_remote_storage_details(request):
+    """ Fetches the remote storage details and returns """
+    try:
+        result = fetch_remote_storage_details()
+
+        if result:
+            return HttpResponse(json.dumps(result),
+                                content_type="application/json")
+        else:
+            return HttpResponse(json.dumps({"message": "No Backups scheduled!"}),
+                                content_type="application/json", status=204)
+
+    except Exception as e:
+        oper_log('error', 'system', "Exception while fetching remote storage details.")
+        message = str(e.message).replace("'", "")
+        message = 'Exception while fetching remote storage details,  details: {}'.format(message)
+        return HttpResponse(json.dumps({
+            "message": "Error while fetching remote storage details",
+            "details": "{}".format(message)
+        }), content_type="application/json", status=500)
+
+
 restore_handlers = {
     ('start', 'POST'): start_backup,
-    ('status', 'GET'): backup_status,
+    ('status', 'GET'): get_backup_status,
     ('download', 'GET'): download_backup,
+    ('files', 'GET'): get_backup_file_list,
+    ('file', 'DELETE'): remove_backup_file,
     ('schedule', 'POST'): schedule_backup,
     ('schedule', 'GET'): get_schedule_backup_info,
     ('schedule', 'DELETE'): remove_backup_cron_job,
+    ('remote_storage', 'POST'): save_remote_storage_details,
+    ('remote_storage', 'GET'): get_remote_storage_details
 
 }
 
@@ -179,6 +236,8 @@
         if handler:
             if handler is download_backup:
                 return download_backup(request.GET.get('filename'))
+            elif handler is remove_backup_file:
+                return remove_backup_file(request.GET.get('filename'))
             else:
                 return handler(request)
         else:
Index: /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/controller/restore_controller.py
===================================================================
--- /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/controller/restore_controller.py	(revision 2496)
+++ /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/controller/restore_controller.py	(working copy)
@@ -8,31 +8,13 @@
 from hive.utils import andebug, get_current_session
 from hive.services.restore_service import RestoreConfig
 from hive.session import ANSession
-
-RESTORE_LOG_FILE = "/var/log/restore.log"
+from hive.services.service_utils import ServiceUtils
 
 
 def handle_restore_req(request, path=None):
     try:
         if path == 'start' and request.method == 'POST':
-            obj = request.body
-            obj = json.loads(obj)
-            if 'filename' in obj:
-                uploaded_filename = obj['filename']
-                filename = os.path.join("/tmp/webui_upload/" + uploaded_filename)
-
-                if not filename.endswith("tar.gz"):
-                    return HttpResponse(json.dumps({
-                        'error': 400,
-                        'message': "Invalid file type. please upload file with extension tar.gz"
-                    }), content_type='application/json', status=400)
-
-                return restore_backup(filename, request)
-            else:
-                return HttpResponse(json.dumps({
-                    'error': 400,
-                    'message': "No file uploaded"
-                }), content_type='application/json', status=400)
+            return restore_backup(request)
 
         elif path == 'status' and request.method == 'GET':
             return restore_status(request)
@@ -52,18 +34,52 @@
         raise ge.GenericError(500, e.message)
 
 
-def restore_backup(file, request):
+def restore_backup(request):
     """ Restore Backup"""
+    data = json.loads(request.body)
     restore_config = RestoreConfig()
     try:
+        if 'filename' in data:
+            filename = data.get('filename')
+        else:
+            return HttpResponse(json.dumps({
+                'error': 400,
+                'message': "Filename not specified"
+            }), content_type='application/json', status=400)
+
+        if not filename.endswith("tar.gz"):
+            return HttpResponse(json.dumps({
+                'error': 400,
+                'message': "Invalid file type. please upload file with extension tar.gz"
+            }), content_type='application/json', status=400)
+
         session = get_current_session()
         # Since the file upload during restore is taking a long time _thread_locals in utils.py is not initialized
         # with session id when we start the restore. So getting the session object specifically here in case the
         # get_current_session does not return session object
         if session is None:
             session = ANSession.find_session_by_id(request.COOKIES['hive_sess'])
-        restore_config.restore_backup_config(file, session)
-        return HttpResponse(json.dumps({"message": "Restore completed."}), content_type='application/json')
+
+        data = json.loads(request.body)
+        backup_target = data.get("backup_target")
+        if not backup_target:
+            return HttpResponse(json.dumps({
+                'error': 400,
+                'message': "Back up destination not specified. Please specify value for 'backup_target'"
+            }), content_type='application/json', status=400)
+
+        if not (backup_target == ServiceUtils.LOCAL or backup_target == ServiceUtils.REMOTE):
+            return HttpResponse(json.dumps({
+                'error': 400,
+                'message': "Incorrect value specified for 'backup_target'.",
+                'description': "Please use 'local' or 'remote' value for 'backup_target'"
+            }), content_type='application/json', status=400)
+
+        response = restore_config.restore_backup_config(filename, session, backup_target)
+        if response:
+            return response
+        else:
+            return HttpResponse(json.dumps({"message": "Restore completed."}), content_type='application/json')
 
     except Exception as e:
         message = str(e.message).replace("'", "")
@@ -75,7 +91,7 @@
 def restore_status(request):
     """ Fetch the status of the restore """
     try:
-        with open(RESTORE_LOG_FILE, 'r') as restore_file:
+        with open(ServiceUtils.RESTORE_LOG_FILE, 'r') as restore_file:
             logs = restore_file.readlines()[-2:]
     except IOError as e:
         message = str(e.message).replace("'", "")
@@ -107,5 +123,4 @@
 
     return HttpResponse(json.dumps({
         "status": "In-Progress",
-        "message": "Restore in Progress!"}), content_type='application/json')
-
+        "message": "Restore in Progress!"}), content_type='application/json')
\ No newline at end of file
Index: /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/services/backup_service.py
===================================================================
--- /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/services/backup_service.py	(revision 2496)
+++ /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/services/backup_service.py	(working copy)
@@ -6,56 +6,65 @@
 import logging
 import sys
 import json
+import time
 
 sys.path.append('/ca/webui/htdocs/new/src')
 from cm.lib.libbasic_operation import oper_log
 from service_utils import ServiceUtils
 from hive.utils import andebug
 from hive.custom_exceptions import generic_exception as ge
+from hive.services.backup_service_utils import fetch_remote_storage_details
+from cm.lib.postgres_db import DB
+from django.http import HttpResponse
 
 BACKUP_TIMESTAMP = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
-BACKUP_DIR = "/tmp/product_backup_" + BACKUP_TIMESTAMP
+TMP_BACKUP_DIR = "/tmp/product_backup_" + BACKUP_TIMESTAMP
 BACKUP_FILE = "backup_" + BACKUP_TIMESTAMP + ".tar.gz"
-SHOW_RUN_FILE = os.path.join(BACKUP_DIR, "show_run_" + BACKUP_TIMESTAMP + ".log")
+SHOW_RUN_FILE = os.path.join(TMP_BACKUP_DIR, "show_run_" + BACKUP_TIMESTAMP + ".log")
+BACKUP_DIR = "/var/backups/"
 
 # Configure Logging
 backup_logger = logging.getLogger("backup_logger")
-backup_logger.setLevel(logging.INFO)
 
-# Defining a file handler for the logs
-file_handler = logging.FileHandler(ServiceUtils.BACKUP_LOG_FILE)
-file_handler.setFormatter(logging.Formatter("%(asctime)s - %(message)s", "%Y-%m-%d %H:%M:%S"))
+INSERT_BCKFILE_SQL_STR = """INSERT INTO backups (filename, status) VALUES('{}', '{}')"""
+UPDATE_BCKFILE_SQL_STR = """UPDATE backups SET status='{}' WHERE filename='{}'"""
+DELETE_BCKFILE_SQL_STR = """DELETE FROM backups WHERE filename='{}'"""
+
+if not backup_logger.handlers:
+    backup_logger.setLevel(logging.INFO)
+
+    # Defining a file handler for the logs
+    file_handler = logging.FileHandler(ServiceUtils.BACKUP_LOG_FILE)
+    file_handler.setFormatter(logging.Formatter("%(asctime)s - %(message)s", "%Y-%m-%d %H:%M:%S"))
 
-backup_logger.addHandler(file_handler)
+    backup_logger.addHandler(file_handler)
 
 
 class BackupConfig:
     def __init__(self):
         pass
 
-    def perform_backup(self):
+    def perform_backup(self, destination):
         """ Performs the backup process """
         try:
-            os.makedirs(BACKUP_DIR)
+            if not os.path.exists(TMP_BACKUP_DIR):
+                os.makedirs(TMP_BACKUP_DIR)
 
             backup_logger.info("Starting backup...")
+            self.update_backups_db(BACKUP_FILE, "Started", 'insert')
 
             # Backup InfluxDB
             backup_logger.info("Backing up InfluxDB...")
-            influx_backup_path = os.path.join(BACKUP_DIR, "influxdb")
+            influx_backup_path = os.path.join(TMP_BACKUP_DIR, "influxdb")
             os.makedirs(influx_backup_path)
             ServiceUtils.run_command(
                 "/usr/local/bin/composer/influxd backup -portable -database {} {}"
                 .format(ServiceUtils.INFLUX_DB, influx_backup_path), backup_logger)
-
-            # Backup PostgreSQL
-            backup_logger.info("Backing up PostgreSQL...")
-            ServiceUtils.run_command("/usr/pgsql-10/bin/pg_dump -U {} -h {} -p {} {} -F c -f {}/postgres_backup.dump".format(
-                ServiceUtils.POSTGRES_USER, ServiceUtils.POSTGRES_HOST, ServiceUtils.POSTGRES_PORT, ServiceUtils.POSTGRES_DB, BACKUP_DIR), backup_logger)
+            self.update_backups_db(BACKUP_FILE, "In-progress", 'update')
 
             # Backup SQLite
             backup_logger.info("Backing up SQLite...")
-            shutil.copy(ServiceUtils.SQLITE_FILE, BACKUP_DIR)
+            shutil.copy(ServiceUtils.SQLITE_FILE, TMP_BACKUP_DIR)
 
             # Backup 'show run' configuration
             backup_logger.info("Backing up 'show run' configuration...")
@@ -68,26 +77,67 @@
                 backup_logger.info("'show run' backup failed! Error: " + str(e))
                 e.message = "'show run' backup failed!"
                 raise e
+            self.update_backups_db(BACKUP_FILE, "In-progress", 'update')
 
             # Backup system logs
             backup_logger.info("Backing up system logs...")
-            exclude_dirs = ["elasticsearch", "composer*.log", "vmware-network*.log", "yum*.log"]
+            exclude_dirs = ["elasticsearch", "composer*.log", "vmware-network*.log", "yum*.log", "backup.log"
+                            , "restore.log"]
             exclude_flags = " ".join(["--exclude=" + d for d in exclude_dirs])
-            ServiceUtils.run_command("rsync -av {} /var/log/ {}/logs/".format(exclude_flags, BACKUP_DIR), backup_logger)
+            ServiceUtils.run_command("rsync -av {} /var/log/ {}/logs/".format(exclude_flags, TMP_BACKUP_DIR),
+                                     backup_logger)
+            self.update_backups_db(BACKUP_FILE, "In-progress", 'update')
+
+            backup_file = "/tmp/" + BACKUP_FILE
+            if destination == ServiceUtils.REMOTE:
+                result = fetch_remote_storage_details()
+                # Persist the data in remote storage
+                ip = result['ip']
+                username = result['username']
+                password = result['password']
+                path = result['path']
+
+                if not path:
+                    path = '/tmp'
+
+                path = path if path.endswith("/") else path + "/"
+
+                ServiceUtils.run_command("tar -czvf {} -C {} ."
+                                         .format(backup_file, TMP_BACKUP_DIR), backup_logger)
+
+                ServiceUtils.run_command('sshpass -p {} scp -o StrictHostKeyChecking=no -o '
+                                         'UserKnownHostsFile=/dev/null {} {}@{}:{}'
+                                         .format(password, backup_file, username, ip, path), backup_logger)
+
+            elif destination == ServiceUtils.LOCAL:
+                # Persist the data in local system
+                backup_logger.info("Creating tar archive...")
+                ServiceUtils.run_command("mkdir -p /var/backups", backup_logger)
+                ServiceUtils.run_command("tar -czvf {} -C {} ."
+                                         .format("/var/backups/" + BACKUP_FILE, TMP_BACKUP_DIR), backup_logger)
 
-            # Create tar archive
-            backup_logger.info("Creating tar archive...")
-            ServiceUtils.run_command("mkdir -p /var/backups", backup_logger)
-            ServiceUtils.run_command("tar -czvf {} -C {} ."
-                                     .format("/var/backups/" + BACKUP_FILE, BACKUP_DIR), backup_logger)
+            # Update success status in DB
+            self.update_backups_db(BACKUP_FILE, "Completed", 'update')
+
+
+            # Backup PostgreSQL
+            """ Taking backup of postgres DB after updating DB with the Success message.
+                So that during restore the DB contains correct data """
+            backup_logger.info("Backing up PostgreSQL...")
+            ServiceUtils.run_command(
+                "/usr/pgsql-10/bin/pg_dump -U {} -h {} -p {} {} -F c -f {}/postgres_backup.dump".format(
+                    ServiceUtils.POSTGRES_USER, ServiceUtils.POSTGRES_HOST, ServiceUtils.POSTGRES_PORT,
+                    ServiceUtils.POSTGRES_DB, TMP_BACKUP_DIR), backup_logger)
 
             # Cleanup
             backup_logger.info("Cleaning up backup directory...")
-            shutil.rmtree(BACKUP_DIR, ignore_errors=True)
+            ServiceUtils.run_command("rm -rf {}".format(TMP_BACKUP_DIR), backup_logger)
+            ServiceUtils.run_command("rm -rf {}".format(backup_file), backup_logger)
 
             backup_logger.info("Backup completed: " + BACKUP_FILE)
 
         except Exception as e:
+            self.update_backups_db(BACKUP_FILE, "Failed", 'update')
             backup_logger.error("Backup failed! " + str(e))
             backup_logger.info("Rolling backup changes")
             ServiceUtils.run_command("rm -rf /var/backups/{}".format(BACKUP_FILE), backup_logger)
@@ -95,7 +145,118 @@
             e.message = 'Exception while creating backup,  details: {}'.format(e.message)
             raise ge.GenericError(500, e.message)
 
+    def update_backups_db(self, backup_filename, status, action):
+        """ Updated the status for backup filename in DB """
+        try:
+            db = DB.get_connected_db()
+            sql = ''
+            if action == 'insert':
+                sql = INSERT_BCKFILE_SQL_STR.format(backup_filename, status)
+
+            elif action == 'update':
+                sql = UPDATE_BCKFILE_SQL_STR.format(status, backup_filename)
+
+            elif action == 'delete':
+                sql = DELETE_BCKFILE_SQL_STR.format(backup_filename)
+
+            if sql:
+                db.execute_sql(sql)
+            db.close()
+        except Exception as e:
+            oper_log('error', 'system', "Exception while updating backups DB.")
+            message = str(e.message).replace("'", "")
+            message = 'Error while updating backups DB,  details: {}'.format(message)
+            return HttpResponse(json.dumps({
+                "message": "Error while updating backups DB: {}".format(message),
+                "details": "{}".format(message)
+            }), content_type="application/json", status=500)
+
+    def delete_backup_file(self, filename):
+        try:
+
+            backup_logger.info("Deleting filename: {}".format(filename))
+            ServiceUtils.run_command("rm -rf {}".format(BACKUP_DIR + filename),
+                                     backup_logger)  # Deleting file from the system
+            self.update_backups_db(filename, None, 'delete')  # Deleting file from the DB
+            backup_logger.info("Successfully deleted backup file: {}".format(filename))
+
+        except Exception as e:
+            oper_log('error', 'system', "Exception while deleting the backup file: {}.".format(filename))
+            message = str(e.message).replace("'", "")
+            message = 'Error while deleting the backup file: {},  details: {}'.format(filename, message)
+            return HttpResponse(json.dumps({
+                "message": "Error while deleting the backup file: {}".format(filename),
+                "details": "{}".format(message)
+            }), content_type="application/json", status=500)
+
+    def get_backup_files_info(self):
+        try:
+
+            db = DB.get_connected_db()
+            fetch_backup_files_sql = 'SELECT filename, status, time FROM backups'
+            data = db.fetchall(fetch_backup_files_sql)
+
+            result = []
+            if data:
+                key = ['filename', 'status', 'time']
+                # Serialize the result
+                for each in data:
+                    row_dict = dict(zip(key, each))
+                    for (k, v) in row_dict.items():
+                        if isinstance(v, datetime.datetime):
+                            row_dict[k] = v.isoformat()
+                    result.append(row_dict)
+            else:
+                result = None
+
+            if result:
+                return HttpResponse(json.dumps(result),
+                                    content_type="application/json")
+            else:
+                return HttpResponse(json.dumps({"message": "No Backups found!"}),
+                                    content_type="application/json", status=204)
+            db.close()
+
+        except Exception as e:
+            oper_log('error', 'system', "Exception while fetching backup files info.")
+            message = str(e.message).replace("'", "")
+            message = 'Error while fetching backup files info,  details: {}'.format(message)
+            return HttpResponse(json.dumps({
+                "message": "while fetching backup files info",
+                "details": "{}".format(message)
+            }), content_type="application/json", status=500)
+
+    def get_backup_status(self):
+        try:
+            db = DB.get_connected_db()
+            fetch_backup_files_sql = 'SELECT status FROM backups'
+            data = db.fetchall(fetch_backup_files_sql)
+
+            if data:
+                key = ['status']
+                result = [dict(zip(key, each)) for each in data]
+            else:
+                result = None
+
+            if any(row.get('status') == 'In-progress' for row in result):
+                return HttpResponse(json.dumps({"status": "In-progress",
+                                                "details": "Currently a Backup is in progress"}),
+                                    content_type="application/json")
+            else:
+                return HttpResponse(json.dumps({"status": "Completed",
+                                                "details": "No Backup in progress!"}),
+                                    content_type="application/json")
+            db.close()
+        except Exception as e:
+            oper_log('error', 'system', "Exception while fetching backup status.")
+            message = str(e.message).replace("'", "")
+            message = 'Error while fetching backup status,  details: {}'.format(message)
+            return HttpResponse(json.dumps({
+                "message": "Error while fetching backup status.",
+                "details": "{}".format(message)
+            }), content_type="application/json", status=500)
+
 
 if __name__ == "__main__":
     backup = BackupConfig()
-    backup.perform_backup()
+    backup.perform_backup()
\ No newline at end of file
Index: /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/services/backup_service_utils.py
===================================================================
--- /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/services/backup_service_utils.py	(revision 0)
+++ /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/services/backup_service_utils.py	(working copy)
@@ -0,0 +1,60 @@
+import os
+import json
+import logging
+
+from django.http import HttpResponse
+from hive.custom_exceptions import generic_exception as ge
+from cm.lib.libbasic_operation import oper_log
+from hive.utils import andebug, get_current_session
+from hive.services.service_utils import ServiceUtils
+from cm.lib.postgres_db import DB
+
+
+def persist_remote_storage_details(ip, username, passwd, path):
+    try:
+        "Persist remote storage details in DB"
+        db = DB.get_connected_db()
+        fetch_remote_storage_sql = "SELECT * FROM remote_storage"
+        data = db.fetchall(fetch_remote_storage_sql)
+
+        if not data:
+            insert_remote_storage_sql = ("INSERT INTO remote_storage (ip, username, password, path) "
+                                         "VALUES('{}', '{}', '{}', '{}')").format(ip, username, passwd, path)
+            db.execute_sql(insert_remote_storage_sql)
+        else:
+            row_id = data[0][0]
+            update_remote_storage_sql = ("UPDATE remote_storage SET ip='{}', username='{}', password='{}', path='{}'"
+                                         " WHERE id={}").format(ip, username, passwd, path, row_id)
+            db.execute_sql(update_remote_storage_sql)
+
+        db.close()
+
+        return HttpResponse(json.dumps({"message": "Updated remote storage details successfully!"}),
+                            content_type="application/json")
+    except Exception as e:
+        oper_log('error', 'system', "Exception while saving remote storage details.")
+        message = str(e.message).replace("'", "")
+        message = 'Exception while saving remote storage details,  details: {}'.format(message)
+        return HttpResponse(json.dumps({
+            "message": "Error while updating remote storage details",
+            "details": "{}".format(message)
+        }), content_type="application/json", status=500)
+
+
+def fetch_remote_storage_details():
+    """ Fetches the remote storage details from the DB """
+    try:
+        db = DB.get_connected_db()
+        fetchall_sql = '''SELECT ip, username, password, path FROM remote_storage'''
+        data = db.fetchall(fetchall_sql)
+
+        if data:
+            key = ['ip', 'username', 'password', 'path']
+            result = dict(zip(key, data[0]))
+        else:
+            result = None
+
+        return result
+
+    except Exception as e:
+        raise e
\ No newline at end of file
Index: /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/services/restore_service.py
===================================================================
--- /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/services/restore_service.py	(revision 2496)
+++ /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/services/restore_service.py	(working copy)
@@ -6,32 +6,26 @@
 import sys
 import logging
 import json
+import time
 from django.http import HttpResponse
 from hive.utils import andebug, get_current_session
 from hive.services.service_utils import ServiceUtils
 from hive.custom_exceptions import generic_exception as ge
+from hive.services.backup_service_utils import fetch_remote_storage_details
 
 sys.path.append('/ca/webui/htdocs/new/src')
 from cm.lib.libbasic_operation import oper_log
 
 TIMESTAMP = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
 RESTORE_DIR = "/tmp/restore"
-RESTORE_LOG_FILE = "/var/log/restore.log"
-POSTGRES_USER = "postgres"
-POSTGRES_DB = "cm"
-POSTGRES_HOST = "127.0.0.1"
-POSTGRES_PORT = "5432"
-INFLUX_DB = "composer"
-SQLITE_FILE_PATH = "/var/opt/composer/ui/conf/composer.db"
-INFLUX_DIR = "/usr/local/bin/composer/influxd"
+FILE_UPLOAD_PATH = "/tmp/webui_upload/"
 
 # Configure restore logger
 restore_logger = logging.getLogger("restore_logger")
-restore_logger.setLevel(logging.INFO)
-
-file_handler = logging.FileHandler(RESTORE_LOG_FILE)
-file_handler.setFormatter(logging.Formatter("%(asctime)s - %(message)s"))
 
+restore_logger.setLevel(logging.INFO)
+file_handler = logging.FileHandler(ServiceUtils.RESTORE_LOG_FILE)
+file_handler.setFormatter(logging.Formatter("%(asctime)s - %(message)s", "%Y-%m-%d %H:%M:%S"))
 restore_logger.addHandler(file_handler)
 
 
@@ -39,25 +33,55 @@
     def __init__(self):
         pass
 
-    def restore_backup_config(self, backup_file, session):
+    def restore_backup_config(self, filename, session, destination):
         """ Performs the restore process """
         try:
             if not os.path.exists(RESTORE_DIR):
                 os.makedirs(RESTORE_DIR)
 
-            restore_logger.info("Extracting Backup")
-            with tarfile.open(backup_file, "r:gz") as tar:
-                for member in tar.getmembers():
-                    member_path = os.path.join(RESTORE_DIR, member.name)
-                    if not os.path.abspath(member_path).startswith(os.path.abspath(RESTORE_DIR)):
-                        return json.dumps({
-                            'error': 400,
-                            'message': "Exception while restoring backup. Not a valid backup file"
-                        })
-                tar.extractall(RESTORE_DIR)
+            backup_file = None
+            if destination == ServiceUtils.REMOTE:
+                result = fetch_remote_storage_details()
+                # Persist the data in remote storage
+                ip = result['ip']
+                username = result['username']
+                password = result['password']
+                path = result['path']
+
+                if not path:
+                    path = '/tmp'
+
+                path = path if path.endswith("/") else path + "/"
+                try:
+                    ServiceUtils.run_command('sshpass -p {} scp -o StrictHostKeyChecking=no -o '
+                                         'UserKnownHostsFile=/dev/null {}@{}:{} {}'
+                                         .format(password, username, ip, path + filename, FILE_UPLOAD_PATH + filename),
+                                         restore_logger)
+                except Exception as e:
+                    return HttpResponse(json.dumps({
+                        'error': 404,
+                        'message': "Back up file not found on remote server."
+                    }), content_type='application/json', status=404)
+
+                backup_file = os.path.join(FILE_UPLOAD_PATH + filename)
+                if not os.path.isfile(backup_file):
+                    return HttpResponse(json.dumps({
+                        'error': 404,
+                        'message': "Back up file not found. Please upload the file using upload api."
+                    }), content_type='application/json', status=404)
+                self.extract_backup_file(backup_file)
+
+            elif destination == ServiceUtils.LOCAL:
+                backup_file = os.path.join(FILE_UPLOAD_PATH + filename)
+                if not os.path.isfile(backup_file):
+                    return HttpResponse(json.dumps({
+                        'error': 404,
+                        'message': "Back up file not found. Please upload the file using upload api."
+                    }), content_type='application/json', status=404)
+                self.extract_backup_file(backup_file)
 
             restore_logger.info("Restoring InfluxDB")
-            if os.path.exists(INFLUX_DIR):
+            if os.path.exists(ServiceUtils.INFLUX_DIR):
                 cmd = "/usr/local/bin/composer/influx -execute 'DROP DATABASE composer'"
                 ServiceUtils.run_command(cmd, restore_logger)
                 influx_backup_path = os.path.join(RESTORE_DIR, "influxdb")
@@ -70,8 +94,8 @@
             restore_logger.info("Restoring Postgres DB")
             pg_dump = os.path.join(RESTORE_DIR, "postgres_backup.dump")
             if os.path.exists(pg_dump):
-                cmd = ("/usr/pgsql-10/bin/pg_restore -U {} -h {} -p {} -d {} -c {}".format(POSTGRES_USER, POSTGRES_HOST,
-                                                                                           POSTGRES_PORT, POSTGRES_DB,
+                cmd = ("/usr/pgsql-10/bin/pg_restore -U {} -h {} -p {} -d {} -c {}".format(ServiceUtils.POSTGRES_USER, ServiceUtils.POSTGRES_HOST,
+                                                                                           ServiceUtils.POSTGRES_PORT, ServiceUtils.POSTGRES_DB,
                                                                                            pg_dump))
                 ServiceUtils.run_command(cmd, restore_logger)
                 restore_logger.info("Postgres DB restored successfully.")
@@ -81,7 +105,7 @@
             restore_logger.info("Restoring SQLite DB")
             sqlite_backup = os.path.join(RESTORE_DIR, "composer.db")
             if os.path.exists(sqlite_backup):
-                shutil.copy(sqlite_backup, SQLITE_FILE_PATH)
+                shutil.copy(sqlite_backup, ServiceUtils.SQLITE_FILE)
                 restore_logger.info("SQLite DB restored successfully.")
             else:
                 restore_logger.info("SQLite DB not found.")
@@ -102,10 +126,23 @@
             ServiceUtils.run_command("rsync -av {}/logs/ /var/log/".format(RESTORE_DIR), restore_logger)
 
             restore_logger.info("Restore completed")
-            return HttpResponse(json.dumps({"message": "Restore completed."}), content_type='application/json')
+
+            time.sleep(5)
+            os.system("shutdown -r +1")
 
         except Exception as e:
             restore_logger.info("Restoring backup failed! " + str(e))
             oper_log('error', 'system', "Exception while creating restoring backup.")
-            e.message = 'Exception while restoring backup.,  details: {}'.format(str(e.message))
-            raise ge.GenericError(400, e.message)
\ No newline at end of file
+            raise ge.GenericError(400, str(e.message))
+
+    def extract_backup_file(self, backup_file):
+        restore_logger.info("Extracting Backup")
+        with tarfile.open(backup_file, "r:gz") as tar:
+            for member in tar.getmembers():
+                member_path = os.path.join(RESTORE_DIR, member.name)
+                if not os.path.abspath(member_path).startswith(os.path.abspath(RESTORE_DIR)):
+                    return json.dumps({
+                        'error': 400,
+                        'message': "Exception while restoring backup. Not a valid backup file"
+                    })
+            tar.extractall(RESTORE_DIR)
\ No newline at end of file
Index: /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/services/schedule_backup.py
===================================================================
--- /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/services/schedule_backup.py	(revision 2496)
+++ /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/services/schedule_backup.py	(working copy)
@@ -43,12 +43,14 @@
             )
             db.execute_sql(insert_sql)
         else:
+            row_id = data[0][0]
             update_sql = """UPDATE backup_schedule set frequency='{}', time='{}', day_of_the_month={}, day_of_the_week={},
-            month={} where id = 1""".format(
+            month={} where id = {}""".format(
                 frequency, time_str,
                 "NULL" if day_of_the_month is None else day_of_the_month,
                 "NULL" if day_of_the_week is None else day_of_the_week,
-                "NULL" if month is None else month
+                "NULL" if month is None else month,
+                row_id
             )
             db.execute_sql(update_sql)
         db.close()
Index: /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/services/service_utils.py
===================================================================
--- /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/services/service_utils.py	(revision 2496)
+++ /branches/amp_3_7/src/webui/webui/htdocs/new/src/hive/services/service_utils.py	(working copy)
@@ -5,7 +5,7 @@
 
 class ServiceUtils:
     # Set Variables
-    BACKUP_LOG_FILE = "/var/log/backup.log"
+    BACKUP_LOG_FILE = "/var/backup.log"
     BACKUP_CRON_LOG_FILE = "/var/log/backup_cron.log"
     POSTGRES_USER = "postgres"
     POSTGRES_DB = "cm"
@@ -18,6 +18,10 @@
     WEEKLY = "weekly"
     MONTHLY = "monthly"
     YEARLY = "yearly"
+    LOCAL = 'local'
+    REMOTE = 'remote'
+    RESTORE_LOG_FILE = "/var/restore.log"
+    INFLUX_DIR = "/usr/local/bin/composer/influxd"
 
     def __init__(self):
         pass
