forked from leo-project/leofs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mv_avs_dir.sh
executable file
·137 lines (121 loc) · 3.2 KB
/
mv_avs_dir.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/sh
## ======================================================================
##
## LeoFS
##
## Copyright (c) 2012-2017 Rakuten, Inc.
##
## This file is provided to you under the Apache License,
## Version 2.0 (the "License"); you may not use this file
## except in compliance with the License. You may obtain
## a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing,
## software distributed under the License is distributed on an
## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
## KIND, either express or implied. See the License for the
## specific language governing permissions and limitations
## under the License.
##
## ======================================================================
## 'mv_avs_dir' which can be used to change the data directory.
##
## You just specify the current directory and the destination directory,
## and you need to modify the leo_storage configuration, 'obj_containers.path '
## before re-launching the LeoStorage node.
##
## Note: You need to stop a target LeoStorage node before executing 'mv_avs_dir'.
## ======================================================================
bold=`tput bold`
normal=`tput sgr0`
NONE='\033[00m'
BOLD='\033[1m'
UNDERLINE='\033[4m'
SCRIPT=`basename $0`
DIR_LOG="log"
DIR_OBJ="object"
DIR_METADATA="metadata"
## ------------------------------------
## Common Functions
## ------------------------------------
output() {
echo "$1"
}
usage() {
output "usage: ${bold}$SCRIPT${normal} <source-directory> <destination-directory>"
}
## Operates files
## - Removes current similinks
## - Creates new simlinks
## @param destination-directory
## @param delimiter
##
op_files() {
dir=$1
cd "$dir"
for i in *
do
f=$i
if [ -L "$f" ] ; then
l=`readlink "$f"`
l=${l%/}
l=${l##*/}
rm "$f"
source_file="$l"
target_file="$f"
ln -fs "$source_file" "$target_file"
echo "[CREATED] $dir/$source_file > $dir/$target_file"
fi
done
cd -
}
## ------------------------------------
## Validation
## ------------------------------------
if [ $# -ne 2 ]; then
usage
exit 1
fi
cur=$(pwd)
src=${1%/}
dest=${2%/}
if [ -e $src ]; then
if [ -d $src ]; then
if [ -e $dest ]; then
if [ -d $dest ]; then
echo "::: LeoFS / move-avs-directories :::"
echo ""
echo "[INFO]"
echo " Src dir: $src"
echo " Dest dir: $dest"
echo ""
else
echo "[ERROR] $dest is NOT directory"
exit 1
fi
else
echo "[ERROR] $dest NOT Found"
exit 1
fi
else
echo "[ERROR] $src is NOT directory"
exit 1
fi
else
echo "[ERROR] $src NOT Found"
exit 1
fi
## ------------------------------------
## Processing For Destination Dir
## ------------------------------------
## @TODO
## mv $src/* $dest/
cp -pR $src/* $dest/
##
## Operates files
##
op_files "$dest/$DIR_LOG" "."
op_files "$dest/$DIR_OBJ" "_"
op_files "$dest/$DIR_METADATA" "_"