Browse Source

Fix for skip + Example adaptions

master
Dirk Alders 3 years ago
parent
commit
bb0f44652e
4 changed files with 44 additions and 16 deletions
  1. 22
    0
      .gitignore
  2. 6
    5
      example/backup_config.py
  3. 11
    9
      example/sync_config.py
  4. 5
    2
      mysync

+ 22
- 0
.gitignore View File

1
+config.py
2
+
3
+# ---> Eclipse
4
+.project
5
+.pydevproject
6
+.settings
7
+
8
+# ---> Linux
9
+*~
10
+
11
+# temporary files which can be created if a process still has a handle open of a deleted file
12
+.fuse_hidden*
13
+
14
+# KDE directory preferences
15
+.directory
16
+
17
+# Linux trash folder which might appear on any partition or disk
18
+.Trash-*
19
+
20
+# .nfs files are created when an open file is removed but is still being accessed
21
+.nfs*
22
+
1
 # ---> Python
23
 # ---> Python
2
 # Byte-compiled / optimized / DLL files
24
 # Byte-compiled / optimized / DLL files
3
 __pycache__/
25
 __pycache__/

+ 6
- 5
example/backup_config.py View File

2
 import sys
2
 import sys
3
 
3
 
4
 backup = True
4
 backup = True
5
-backup_basepath = '/data/backup/ahorn'
5
+host = 'erle'
6
+backup_basepath = '/data/backup/data'
6
 
7
 
7
 installations = ['mint', 'kubuntu', 'openSuSE']
8
 installations = ['mint', 'kubuntu', 'openSuSE']
8
 for installation in installations:
9
 for installation in installations:
9
-    setattr(sys.modules[__name__], 'home_%s_remotepath' % installation, 'dirk@ahorn:/home')
10
+    setattr(sys.modules[__name__], 'home_%s_remotepath' % installation, 'dirk@%s:/home' % host)
10
     setattr(sys.modules[__name__], 'home_%s_localpath' % installation, os.path.join(installation, 'home'))
11
     setattr(sys.modules[__name__], 'home_%s_localpath' % installation, os.path.join(installation, 'home'))
11
 
12
 
12
-user_data_remotepath = 'dirk@ahorn:/user_data'
13
-user_data_localpath = 'user_data'
14
-user_data_skip = ['static_data']
13
+data_remotepath = 'dirk@%s:/usr/data' % host
14
+data_localpath = 'usr/data'
15
+data_skip = ['lost+found', 'dirk/Audio', 'dirk/bin', 'dirk/gnome-boxes', 'dirk/media_images', 'dirk/Videos']

+ 11
- 9
example/sync_config.py View File

4
 backup = False
4
 backup = False
5
 
5
 
6
 hosts = ['ahorn', 'erle', 'linde']
6
 hosts = ['ahorn', 'erle', 'linde']
7
-__basepath__ = '/user_data'
7
+__basepath__ = '/usr/data'
8
 entries = (
8
 entries = (
9
-    ('dirk@%s:/user_data/bin', os.path.join(__basepath__, 'bin'), None),
10
-    ('dirk@%s:/user_data/data', os.path.join(__basepath__, 'data'), None),
11
-    ('dirk@%s:/user_data/static_data', os.path.join(__basepath__, 'static_data'), ['Audio', 'timeshift', 'lost+found']),
9
+    ('dirk@%s:/usr/data', __basepath__, ['lost+found']),
10
+    ('dirk@%s:/usr/data', __basepath__, ['lost+found', 'dirk/Audio', 'dirk/bin', 'dirk/Downloads', 'dirk/gnome-boxes', 'dirk/media_images', 'dirk/Videos']),
12
     ('dirk@%s:/home', '/home', None),
11
     ('dirk@%s:/home', '/home', None),
13
 )
12
 )
14
 
13
 
15
 
14
 
16
 for host in hosts:
15
 for host in hosts:
17
     for remote, local, skip in entries:
16
     for remote, local, skip in entries:
18
-        setattr(sys.modules[__name__], host + '_' + os.path.basename(local) + '_remotepath', remote % host)
19
-        setattr(sys.modules[__name__], host + '_' + os.path.basename(local) + '_localpath', local)
17
+        name = os.path.basename(local)
20
         if skip is not None:
18
         if skip is not None:
21
-            setattr(sys.modules[__name__], host + '_' + os.path.basename(local) + '_skip', skip)
19
+            if len(skip) > 1:
20
+                name += '_short'
21
+            setattr(sys.modules[__name__], host + '_' + name + '_skip', skip)
22
+        setattr(sys.modules[__name__], host + '_' + name + '_remotepath', remote % host)
23
+        setattr(sys.modules[__name__], host + '_' + name + '_localpath', local)
22
 
24
 
23
 
25
 
24
-mount_mockery_audio_remotepath = 'root@mount-mockery.de:/data/audio/items'
25
-mount_mockery_audio_localpath = os.path.join(__basepath__, 'static_data', 'dirk', 'Audio')
26
+mount_mockery_audio_remotepath = 'root@mount-mockery.de:/data/audio'
27
+mount_mockery_audio_localpath = os.path.join(__basepath__, 'dirk', 'Audio')

+ 5
- 2
mysync View File

10
 
10
 
11
 DEBUG = False
11
 DEBUG = False
12
 
12
 
13
-RSYNC_REMOTE_COMMAND = 'sudo rsync'
13
+RSYNC_REMOTE_COMMAND = 'rsync'
14
 TIME_FORMAT = "%Y-%m-%d_%H-%M-%S"
14
 TIME_FORMAT = "%Y-%m-%d_%H-%M-%S"
15
 try:
15
 try:
16
     basepath = config.backup_basepath
16
     basepath = config.backup_basepath
70
         skip = kwargs.get(PROP_SKIP)
70
         skip = kwargs.get(PROP_SKIP)
71
         cmd_l = ['rsync', '-avn' if DEBUG else '-av', '--delete', '--rsync-path="%s"' % RSYNC_REMOTE_COMMAND, remotepath, localpath]
71
         cmd_l = ['rsync', '-avn' if DEBUG else '-av', '--delete', '--rsync-path="%s"' % RSYNC_REMOTE_COMMAND, remotepath, localpath]
72
         if skip is not None:
72
         if skip is not None:
73
-            cmd_l.append('--exclude=%s' % ','.join(skip))
73
+            for skip_dir in skip:
74
+                if not skip_dir.endswith('/'):
75
+                    skip_dir += '/'
76
+                cmd_l.append('--exclude=%s' % skip_dir)
74
         if not os.path.exists(localpath):
77
         if not os.path.exists(localpath):
75
             return 'mkdir -p %s && ' % localpath + ' '.join(cmd_l)
78
             return 'mkdir -p %s && ' % localpath + ' '.join(cmd_l)
76
         return ' '.join(cmd_l)
79
         return ' '.join(cmd_l)

Loading…
Cancel
Save