Browse Source

Add a backup function that will backup all the file on the device to a destination path on the host.

Godzil 3 years ago
parent
commit
1d504a7b45
2 changed files with 20 additions and 0 deletions
  1. 10 0
      nodemcu_uploader/main.py
  2. 10 0
      nodemcu_uploader/uploader.py

+ 10 - 0
nodemcu_uploader/main.py

@@ -168,6 +168,12 @@ def main_func():
         dest='operation',
         help='Run nodemcu-uploader {command} -h for additional help')
 
+    backup_parser = subparsers.add_parser(
+        'backup',
+        help='Backup all the files on the nodemcu board')
+    backup_parser.add_argument('path', help='Folder where to store the backup')
+
+
     upload_parser = subparsers.add_parser(
         'upload',
         help='Path to one or more files to be uploaded. Destination name will be the same as the file name.')
@@ -287,5 +293,9 @@ def main_func():
             uploader.node_heap()
         elif args.ncmd == 'restart':
             uploader.node_restart()
+
+    elif args.operation == 'backup':
+        uploader.backup(args.path)
+
     #no uploader related commands after this point
     uploader.close()

+ 10 - 0
nodemcu_uploader/uploader.py

@@ -470,3 +470,13 @@ class Uploader(object):
         res = self.__exchange(cmd)
         log.info(res)
         return res
+
+    def backup(self, path):
+        """Backup all files from the device"""
+        log.info('Backing up in '+path)
+        # List file to backup
+        files = self.file_list()
+        # then download each of then
+        self.prepare()
+        for f in files:
+            self.read_file(f[0], os.path.join(path, f[0]))