glusterfs

Форк
0
/
glusterfs-georep-upgrade.py 
75 строк · 3.2 Кб
1
#!/usr/bin/python3
2
"""
3

4
Copyright (c) 2020 Red Hat, Inc. <http://www.redhat.com>
5
This file is part of GlusterFS.
6

7
This file is licensed to you under your choice of the GNU Lesser
8
General Public License, version 3 or any later version (LGPLv3 or
9
later), or the GNU General Public License, version 2 (GPLv2), in all
10
cases as published by the Free Software Foundation.
11

12
"""
13

14
import argparse
15
import errno
16
import os, sys
17
import shutil
18
from datetime import datetime
19

20
def find_htime_path(brick_path):
21
    dirs = []
22
    htime_dir = os.path.join(brick_path, '.glusterfs/changelogs/htime')
23
    for file in os.listdir(htime_dir):
24
        if os.path.isfile(os.path.join(htime_dir,file)) and file.startswith("HTIME"):
25
            dirs.append(os.path.join(htime_dir, file))
26
        else:
27
            raise FileNotFoundError("%s unavailable" % (os.path.join(htime_dir, file)))
28
    return dirs
29

30
def modify_htime_file(brick_path):
31
    htime_file_path_list = find_htime_path(brick_path)
32

33
    for htime_file_path in htime_file_path_list:
34
        changelog_path = os.path.join(brick_path, '.glusterfs/changelogs')
35
        temp_htime_path = os.path.join(changelog_path, 'htime/temp_htime_file')
36
        with open(htime_file_path, 'r') as htime_file, open(temp_htime_path, 'w') as temp_htime_file:
37
            #extract epoch times from htime file
38
            paths = htime_file.read().split("\x00")
39

40
            for pth in paths:
41
                epoch_no = pth.split(".")[-1]
42
                changelog = os.path.basename(pth)
43
                #convert epoch time to year, month and day
44
                if epoch_no != '':
45
                    date=(datetime.fromtimestamp(float(int(epoch_no))).strftime("%Y/%m/%d"))
46
                    #update paths in temp htime file
47
                    temp_htime_file.write("%s/%s/%s\x00" % (changelog_path, date, changelog))
48
                    #create directory in the format year/month/days
49
                    path = os.path.join(changelog_path, date)
50

51
                if changelog.startswith("CHANGELOG."):
52
                    os.makedirs(path, mode = 0o600, exist_ok = True)
53

54
                    #copy existing changelogs to new directory structure, delete old changelog files
55
                    try:
56
                        shutil.copyfile(pth, os.path.join(path, changelog))
57
                    except shutil.SameFileError:
58
                        pass
59
                    else:
60
                        os.remove(pth)
61

62
        #rename temp_htime_file with htime file
63
        os.rename(htime_file_path, os.path.join('%s.bak'%htime_file_path))
64
        os.rename(temp_htime_path, htime_file_path)
65

66
if __name__ == "__main__":
67
    parser = argparse.ArgumentParser()
68
    parser.add_argument('brick_path', help="This upgrade script, which is to be run on\
69
                         server side, takes brick path as the argument, \
70
                         updates paths inside htime file and alters the directory structure \
71
                         above the changelog files inorder to support new optimised format \
72
                         of the directory structure as per \
73
                         https://review.gluster.org/#/c/glusterfs/+/23733/")
74
    args = parser.parse_args()
75
    modify_htime_file(args.brick_path)
76

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.