1) I saved the code of the below followed script as an example for the following queries for myself:
2) CSV-file was exported from Excel
$ cat ./list.csv
;1.;OVERVIEW (1-11);***;***;***;***;***;;;
1;;text;autor1;reader1;;;;;х
2;;text;autor2;reader2,reader3;Amazon;;;х;;
3;;text;autor1;reader1;;;;;х
4;;text;autor2;reader2,reader3;Amazon;;;х;;
5;;text;autor1;reader2;;;;;х
6;;text;autor2;reader1,reader3;Amazon;;;х;;
7;;text;autor1;reader1;;;;;х
8;;text;autor2;reader2,reader3;Amazon;;;х;;
9;;text;autor1;reader1;;;;;х
10;;text;autor2;reader2,(reader4);Amazon;;;х;;
11;;text;autor1;reader3;;;;;х
;2.;CONTENT (12-26);;***;***;;;;;
12;;text;autor2;reader2,reader4;Amazon;;;х;;
13;;text;autor1;reader1;;;;;х
14;;text;autor1;reader3;;;;;х
15;;text;autor2;reader1,reader4;Amazon;;;х;;
16;;text;autor1;reader1;;;;;х
17;;text;autor2;reader3,reader4;Amazon;;;х;;
18;;text;autor1;reader1;;;;;х
19;;text;autor2;reader2,reader3;Amazon;;;х;;
20;;text;autor1;reader1;;;;;х
21;;text;autor2;reader2,reader3;Amazon;;;х;;
22;;text;autor1;reader1;;;;;х
23;;text;autor2;reader1,reader2;Amazon;;;х;;
24;;text;autor1;reader1;;;;;х
25;;text;autor2;reader1,reader2;Amazon;;;х;;
26;;text;autor1;reader1;;;;;х
3) Script generates the file structure basing on above-stated csv-file:
$ cat ./make_stucture
#!/bin/bash
function make_query_ln {
user=$1;
mkdir -p "$u_path/$user/$level1"
if [ ! -L "$u_path/$user/$level1/$query" ]; then ln -s "$q_path/$level1/$query" "$u_path/$user/$level1/$query"; fi
}
if test $# -ne 1; then
echo "Enter csv file for parsing"
exit 1
fi
s_path="/samba"; q_path="$s_path/comments"; u_path="$s_path/users"; IFS=';'
mkdir -p "$s_path"; mkdir -p "$q_path"; mkdir -p "$u_path"
while read -a array line
do
if [ "${array[0]}" != "" ]; then
if [ "${array[8]}" != "" ]; then
printf -v query "%03i" ${array[0]}
mkdir -p "$q_path/$level1/$query"
if [[ ${array[3]} == *"autor1"* ]]; then make_query_ln "a1"; fi
if [[ ${array[3]} == *"autor2"* ]]; then make_query_ln "a2"; fi
if [[ ${array[4]} == *"reader1"* ]]; then make_query_ln "u1"; fi
if [[ ${array[4]} == *"reader2"* ]]; then make_query_ln "u2"; fi
if [[ ${array[3]} == *"reader3"* ]]; then make_query_ln "u3"; fi
if [[ ${array[4]} == *"reader34"* ]]; then make_query_ln "u3"; fi
if [[ ${array[4]} == *"reader4"* ]] && [[ ${array[4]} != *"(reader4)"* ]]; then make_query_ln "u4"; fi
fi
elif [ "${array[1]}" != "" ]; then level1="${array[1]}${array[2]}"; fi
done < $1
4) The resulting file structure:
$ tree /samba/
/samba/
├── comments
│ ├── 1.OVERVIEW (1-11)
│ │ ├── 002
│ │ ├── 004
│ │ ├── 006
│ │ ├── 008
│ │ └── 010
│ └── 2.CONTENT (12-26)
│ ├── 012
│ ├── 015
│ ├── 017
│ ├── 019
│ ├── 021
│ ├── 023
│ └── 025
└── users
├── a2
│ ├── 1.OVERVIEW (1-11)
│ │ ├── 002 -> /samba/comments/1.OVERVIEW (1-11)/002
│ │ ├── 004 -> /samba/comments/1.OVERVIEW (1-11)/004
│ │ ├── 006 -> /samba/comments/1.OVERVIEW (1-11)/006
│ │ ├── 008 -> /samba/comments/1.OVERVIEW (1-11)/008
│ │ └── 010 -> /samba/comments/1.OVERVIEW (1-11)/010
│ └── 2.CONTENT (12-26)
│ ├── 012 -> /samba/comments/2.CONTENT (12-26)/012
│ ├── 015 -> /samba/comments/2.CONTENT (12-26)/015
│ ├── 017 -> /samba/comments/2.CONTENT (12-26)/017
│ ├── 019 -> /samba/comments/2.CONTENT (12-26)/019
│ ├── 021 -> /samba/comments/2.CONTENT (12-26)/021
│ ├── 023 -> /samba/comments/2.CONTENT (12-26)/023
│ └── 025 -> /samba/comments/2.CONTENT (12-26)/025
├── u1
│ ├── 1.OVERVIEW (1-11)
│ │ └── 006 -> /samba/comments/1.OVERVIEW (1-11)/006
│ └── 2.CONTENT (12-26)
│ ├── 015 -> /samba/comments/2.CONTENT (12-26)/015
│ ├── 023 -> /samba/comments/2.CONTENT (12-26)/023
│ └── 025 -> /samba/comments/2.CONTENT (12-26)/025
├── u2
│ ├── 1.OVERVIEW (1-11)
│ │ ├── 002 -> /samba/comments/1.OVERVIEW (1-11)/002
│ │ ├── 004 -> /samba/comments/1.OVERVIEW (1-11)/004
│ │ ├── 008 -> /samba/comments/1.OVERVIEW (1-11)/008
│ │ └── 010 -> /samba/comments/1.OVERVIEW (1-11)/010
│ └── 2.CONTENT (12-26)
│ ├── 012 -> /samba/comments/2.CONTENT (12-26)/012
│ ├── 019 -> /samba/comments/2.CONTENT (12-26)/019
│ ├── 021 -> /samba/comments/2.CONTENT (12-26)/021
│ ├── 023 -> /samba/comments/2.CONTENT (12-26)/023
│ └── 025 -> /samba/comments/2.CONTENT (12-26)/025
└── u4
└── 2.CONTENT (12-26)
├── 012 -> /samba/comments/2.CONTENT (12-26)/012
├── 015 -> /samba/comments/2.CONTENT (12-26)/015
└── 017 -> /samba/comments/2.CONTENT (12-26)/017
5) Some Samba config notes.
5.1) Default samba shares was deleted.
5.2) Next was added in main conf for symlinks and personal settings:
follow symlinks = yes
wide links = yes
unix extensions = no
include = /etc/samba/smb.conf.%U
5.3) $ cat ./smb.conf.u2
[u2]
path = /var/www/samba/users/u2
browseable = yes
writable = yes
6) The web-structure and part of httpd-configuration.
6.1) $ tree /var/www/html
/var/www/html
├── a2 -> /samba/users/a2
├── u1 -> /samba/users/u1
└── u2 -> /samba/users/u2
6.2) $ cat ./htaccess
AuthUserFile /etc/httpd/conf/.htpasswd
AuthType Basic
AuthName "Privat Sexual Expertise"
require user a2 u1 u2
RewriteEngine on
RewriteCond %{REMOTE_USER} a2
RewriteCond %{REQUEST_URI} !^\/a2\/(.*)$
RewriteRule ^(.*)$ /a2 [L]
RewriteCond %{REMOTE_USER} u1
RewriteCond %{REQUEST_URI} !^\/u1\/(.*)$
RewriteRule ^(.*)$ /u1 [L]
RewriteCond %{REMOTE_USER} u2
RewriteCond %{REQUEST_URI} !^\/u2\/(.*)$
RewriteRule ^(.*)$ /u2 [L]
7) Backup.
7.1) Жаль, в webmin для tar-резервирования не работает опция Just add new files to archive?.
Все файлы повторно добавляются в бэкап, причем старые, а не новые версии.
7.2) Доустанавливаю dump.
Чтобы работала опция Dump level, указываю Update /etc/dumpdates file?.
7.3) Создал в webmin dump-бэкапы с уровнями 0-6 (по уровню на день).
7.4) Просмотр содержимого бэкапа.
7.4.1) restore -if имя_бэкапа (в интерактивном режиме ls маска и т.д.).
7.4.2) В webmin Restore Backup указываю Only show files in backup?.
Работает маска для просматриваемых/восстанавливаемых файлов/каталогов - опция Listed files .. .
- export excel csv
- bash parse string in to array
- bash read file line by line
- bash substring exists
- bash symbolic link
- bash function example
- bash tree
- bash file exists
- bash if and or example
- bash if test example
- bash if else
- bash format string
- bash padded zero
2) CSV-file was exported from Excel
$ cat ./list.csv
;1.;OVERVIEW (1-11);***;***;***;***;***;;;
1;;text;autor1;reader1;;;;;х
2;;text;autor2;reader2,reader3;Amazon;;;х;;
3;;text;autor1;reader1;;;;;х
4;;text;autor2;reader2,reader3;Amazon;;;х;;
5;;text;autor1;reader2;;;;;х
6;;text;autor2;reader1,reader3;Amazon;;;х;;
7;;text;autor1;reader1;;;;;х
8;;text;autor2;reader2,reader3;Amazon;;;х;;
9;;text;autor1;reader1;;;;;х
10;;text;autor2;reader2,(reader4);Amazon;;;х;;
11;;text;autor1;reader3;;;;;х
;2.;CONTENT (12-26);;***;***;;;;;
12;;text;autor2;reader2,reader4;Amazon;;;х;;
13;;text;autor1;reader1;;;;;х
14;;text;autor1;reader3;;;;;х
15;;text;autor2;reader1,reader4;Amazon;;;х;;
16;;text;autor1;reader1;;;;;х
17;;text;autor2;reader3,reader4;Amazon;;;х;;
18;;text;autor1;reader1;;;;;х
19;;text;autor2;reader2,reader3;Amazon;;;х;;
20;;text;autor1;reader1;;;;;х
21;;text;autor2;reader2,reader3;Amazon;;;х;;
22;;text;autor1;reader1;;;;;х
23;;text;autor2;reader1,reader2;Amazon;;;х;;
24;;text;autor1;reader1;;;;;х
25;;text;autor2;reader1,reader2;Amazon;;;х;;
26;;text;autor1;reader1;;;;;х
3) Script generates the file structure basing on above-stated csv-file:
$ cat ./make_stucture
#!/bin/bash
function make_query_ln {
user=$1;
mkdir -p "$u_path/$user/$level1"
if [ ! -L "$u_path/$user/$level1/$query" ]; then ln -s "$q_path/$level1/$query" "$u_path/$user/$level1/$query"; fi
}
if test $# -ne 1; then
echo "Enter csv file for parsing"
exit 1
fi
s_path="/samba"; q_path="$s_path/comments"; u_path="$s_path/users"; IFS=';'
mkdir -p "$s_path"; mkdir -p "$q_path"; mkdir -p "$u_path"
while read -a array line
do
if [ "${array[0]}" != "" ]; then
if [ "${array[8]}" != "" ]; then
printf -v query "%03i" ${array[0]}
mkdir -p "$q_path/$level1/$query"
if [[ ${array[3]} == *"autor1"* ]]; then make_query_ln "a1"; fi
if [[ ${array[3]} == *"autor2"* ]]; then make_query_ln "a2"; fi
if [[ ${array[4]} == *"reader1"* ]]; then make_query_ln "u1"; fi
if [[ ${array[4]} == *"reader2"* ]]; then make_query_ln "u2"; fi
if [[ ${array[3]} == *"reader3"* ]]; then make_query_ln "u3"; fi
if [[ ${array[4]} == *"reader34"* ]]; then make_query_ln "u3"; fi
if [[ ${array[4]} == *"reader4"* ]] && [[ ${array[4]} != *"(reader4)"* ]]; then make_query_ln "u4"; fi
fi
elif [ "${array[1]}" != "" ]; then level1="${array[1]}${array[2]}"; fi
done < $1
4) The resulting file structure:
$ tree /samba/
/samba/
├── comments
│ ├── 1.OVERVIEW (1-11)
│ │ ├── 002
│ │ ├── 004
│ │ ├── 006
│ │ ├── 008
│ │ └── 010
│ └── 2.CONTENT (12-26)
│ ├── 012
│ ├── 015
│ ├── 017
│ ├── 019
│ ├── 021
│ ├── 023
│ └── 025
└── users
├── a2
│ ├── 1.OVERVIEW (1-11)
│ │ ├── 002 -> /samba/comments/1.OVERVIEW (1-11)/002
│ │ ├── 004 -> /samba/comments/1.OVERVIEW (1-11)/004
│ │ ├── 006 -> /samba/comments/1.OVERVIEW (1-11)/006
│ │ ├── 008 -> /samba/comments/1.OVERVIEW (1-11)/008
│ │ └── 010 -> /samba/comments/1.OVERVIEW (1-11)/010
│ └── 2.CONTENT (12-26)
│ ├── 012 -> /samba/comments/2.CONTENT (12-26)/012
│ ├── 015 -> /samba/comments/2.CONTENT (12-26)/015
│ ├── 017 -> /samba/comments/2.CONTENT (12-26)/017
│ ├── 019 -> /samba/comments/2.CONTENT (12-26)/019
│ ├── 021 -> /samba/comments/2.CONTENT (12-26)/021
│ ├── 023 -> /samba/comments/2.CONTENT (12-26)/023
│ └── 025 -> /samba/comments/2.CONTENT (12-26)/025
├── u1
│ ├── 1.OVERVIEW (1-11)
│ │ └── 006 -> /samba/comments/1.OVERVIEW (1-11)/006
│ └── 2.CONTENT (12-26)
│ ├── 015 -> /samba/comments/2.CONTENT (12-26)/015
│ ├── 023 -> /samba/comments/2.CONTENT (12-26)/023
│ └── 025 -> /samba/comments/2.CONTENT (12-26)/025
├── u2
│ ├── 1.OVERVIEW (1-11)
│ │ ├── 002 -> /samba/comments/1.OVERVIEW (1-11)/002
│ │ ├── 004 -> /samba/comments/1.OVERVIEW (1-11)/004
│ │ ├── 008 -> /samba/comments/1.OVERVIEW (1-11)/008
│ │ └── 010 -> /samba/comments/1.OVERVIEW (1-11)/010
│ └── 2.CONTENT (12-26)
│ ├── 012 -> /samba/comments/2.CONTENT (12-26)/012
│ ├── 019 -> /samba/comments/2.CONTENT (12-26)/019
│ ├── 021 -> /samba/comments/2.CONTENT (12-26)/021
│ ├── 023 -> /samba/comments/2.CONTENT (12-26)/023
│ └── 025 -> /samba/comments/2.CONTENT (12-26)/025
└── u4
└── 2.CONTENT (12-26)
├── 012 -> /samba/comments/2.CONTENT (12-26)/012
├── 015 -> /samba/comments/2.CONTENT (12-26)/015
└── 017 -> /samba/comments/2.CONTENT (12-26)/017
5) Some Samba config notes.
5.1) Default samba shares was deleted.
5.2) Next was added in main conf for symlinks and personal settings:
follow symlinks = yes
wide links = yes
unix extensions = no
include = /etc/samba/smb.conf.%U
5.3) $ cat ./smb.conf.u2
[u2]
path = /var/www/samba/users/u2
browseable = yes
writable = yes
6) The web-structure and part of httpd-configuration.
6.1) $ tree /var/www/html
/var/www/html
├── a2 -> /samba/users/a2
├── u1 -> /samba/users/u1
└── u2 -> /samba/users/u2
6.2) $ cat ./htaccess
AuthUserFile /etc/httpd/conf/.htpasswd
AuthType Basic
AuthName "Privat Sexual Expertise"
require user a2 u1 u2
RewriteEngine on
RewriteCond %{REMOTE_USER} a2
RewriteCond %{REQUEST_URI} !^\/a2\/(.*)$
RewriteRule ^(.*)$ /a2 [L]
RewriteCond %{REMOTE_USER} u1
RewriteCond %{REQUEST_URI} !^\/u1\/(.*)$
RewriteRule ^(.*)$ /u1 [L]
RewriteCond %{REMOTE_USER} u2
RewriteCond %{REQUEST_URI} !^\/u2\/(.*)$
RewriteRule ^(.*)$ /u2 [L]
7) Backup.
7.1) Жаль, в webmin для tar-резервирования не работает опция Just add new files to archive?.
Все файлы повторно добавляются в бэкап, причем старые, а не новые версии.
7.2) Доустанавливаю dump.
Чтобы работала опция Dump level, указываю Update /etc/dumpdates file?.
7.3) Создал в webmin dump-бэкапы с уровнями 0-6 (по уровню на день).
7.4) Просмотр содержимого бэкапа.
7.4.1) restore -if имя_бэкапа (в интерактивном режиме ls маска и т.д.).
7.4.2) В webmin Restore Backup указываю Only show files in backup?.
Работает маска для просматриваемых/восстанавливаемых файлов/каталогов - опция Listed files .. .
Комментариев нет:
Отправить комментарий