Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
etersoft-admin-essentials
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
etersoft-admin-essentials
Commits
319831b2
Commit
319831b2
authored
Jul 17, 2015
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eterbackup: refactoring
parent
41dd1b51
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
112 additions
and
52 deletions
+112
-52
eterbackup
backup/eterbackup/eterbackup
+112
-52
No files found.
backup/eterbackup/eterbackup
View file @
319831b2
#!/bin/sh
-x
#!/bin/sh
# Copyright (C) 2015 Etersoft
# Copyright (C) 2015 Vitaly Lipatov <lav@etersoft.ru>
#
...
...
@@ -20,59 +20,32 @@
STZ
=
"000"
STN
=
"???"
extract_dump
()
{
# CHECKME: always exists 000?
find
$DUMPDIR
-type
f
-name
"*.
$STZ
.zpaq"
|
\
while
read
paqfile
;
do
relfile
=
"
${
paqfile
/
$DUMPDIR
\//
}
"
reldir
=
$(
dirname
"
$relfile
"
)
# FIXME: copy dir permissions
# TODO: хранить структуру каталогов отдельно, сразу и проверка?
mkdir
-p
"
$DESTDIR
/
$reldir
"
||
exit
cd
"
$DESTDIR
/
$reldir
/.."
zpaq extract
"
${
paqfile
/.
$STZ
.zpaq/.
$STN
.zpaq
}
"
cd
-
>
/dev/null
done
}
COMMAND
=
$1
# TODO: update, repack
# TODO: -h, --help
shift
case
$COMMAND
in
update|repack
)
;;
extract
)
DUMPDIR
=
$(
realpath
"
$1
"
)
DESTDIR
=
$(
realpath
"
$2
"
)
/
$(
basename
$DUMPDIR
)
extract_dump
exit
;;
-h
|
--help
)
echo
"Run with update <from> <to>"
;;
*
)
exit
1
;;
esac
DEPTH
=
1
if
[
"
$1
"
=
"-depth"
]
||
[
"
$1
"
=
"--depth"
]
;
then
shift
DEPTH
=
$1
shift
fi
DESCR
=
"eterbackup version 0.1 (c) Etersoft 2015"
# from
BACKUPDIR
=
$(
realpath
"
$1
"
)
list_dirs
()
{
#echo "List dirs from $BACKUPDIR, with $EXCLUDEDIR exclude."
# Получаем список каталогов, которые мы хотим превратить в файлы
find
$BACKUPDIR
-depth
-maxdepth
$DEPTH
-mindepth
$DEPTH
-type
d |
\
while
read
subdir
;
do
# TODO: не забыть файлы в основном каталоге
# TODO: неизвестно, как сделать нерекурсивным
# to
DESTDIR
=
$(
realpath
"
$2
"
)
DUMPDIR
=
$DESTDIR
/
$(
basename
"
$BACKUPDIR
"
)
# /var/log/long/something -> long/something
reldir
=
"
${
subdir
/
$BACKUPDIR
\//
}
"
bdir
=
$(
basename
"
$reldir
"
)
# TODO: improve
if
[
"
$bdir
"
=
"
$EXCLUDEDIR
"
]
;
then
echo
"Skip excluded
$bdir
"
continue
fi
echo
"
$reldir
"
done
}
update_dump
()
{
# Получаем список каталогов, которые мы хотим превратить в файлы
find
$BACKUPDIR
-depth
-maxdepth
$DEPTH
-mindepth
$DEPTH
-type
d |
\
while
read
subdir
;
do
...
...
@@ -83,6 +56,12 @@ while read subdir ; do
reldir
=
"
${
subdir
/
$BACKUPDIR
\//
}
"
bdir
=
$(
basename
"
$reldir
"
)
# TODO: improve
if
[
"
$bdir
"
=
"
$EXCLUDEDIR
"
]
;
then
echo
"Skip excluded
$bdir
"
continue
fi
# TODO: удалённые каталоги будут незамечены и останутся.
# Создавать новый слой, копируя со старого, и оставляя тот старыми датами?
...
...
@@ -98,6 +77,9 @@ while read subdir ; do
cd
-
>
/dev/null
;;
repack
)
# TODO: тут нужно сделать другой обход каталогов (готовых)
# TODO: выделить в отдельную функцию
# TODO: check it
zpaq extract
"
$DUMPDIR
/
$reldir
/
$bdir
.
$STN
.zpaq"
-to
"
$DUMPDIR
/
$reldir
/../
$bdir
.
$STZ
.zpaq"
||
exit
rm
-f
$DUMPDIR
/
$reldir
/
$bdir
.
$STN
.zpaq
mv
$DUMPDIR
/
$reldir
/../
$bdir
.
$STZ
.zpaq
$DUMPDIR
/
$reldir
/
$bdir
.
$STZ
.zpaq
...
...
@@ -106,6 +88,84 @@ while read subdir ; do
exit
1
esac
done
}
extract_dump
()
{
# CHECKME: always exists 000?
find
$DUMPDIR
-type
f
-name
"*.
$STZ
.zpaq"
|
\
while
read
paqfile
;
do
relfile
=
"
${
paqfile
/
$DUMPDIR
\//
}
"
reldir
=
$(
dirname
"
$relfile
"
)
# FIXME: copy dir permissions
# TODO: хранить структуру каталогов отдельно, сразу и проверка?
mkdir
-p
"
$DESTDIR
/
$reldir
"
||
exit
cd
"
$DESTDIR
/
$reldir
/.."
zpaq extract
"
${
paqfile
/.
$STZ
.zpaq/.
$STN
.zpaq
}
"
cd
-
>
/dev/null
done
}
COMMAND
=
$1
shift
DEPTH
=
1
if
[
"
$1
"
=
"-depth"
]
||
[
"
$1
"
=
"--depth"
]
;
then
shift
DEPTH
=
$1
shift
fi
EXCLUDEDIR
=
if
[
"
$1
"
=
"--exclude"
]
;
then
shift
EXCLUDEDIR
=
"
$1
"
shift
fi
case
$COMMAND
in
update|repack
)
# from
BACKUPDIR
=
$(
realpath
-e
"
$1
"
)
||
exit
# to
DUMPDIR
=
$(
realpath
-m
"
$2
"
)
update_dump
exit
;;
list
)
# from
BACKUPDIR
=
$(
realpath
-e
"
$1
"
)
||
exit
list_dirs
exit
;;
extract
)
DUMPDIR
=
$(
realpath
-e
"
$1
"
)
||
exit
DESTDIR
=
$(
realpath
-m
"
$2
"
)
/
$(
basename
$DUMPDIR
)
extract_dump
exit
;;
-h
|
--help
)
echo
$DESCR
echo
"Run with
$0
command [options] args"
echo
echo
"Update backup:"
echo
"
$
eterbackup update /path/from /path/to"
echo
echo
"Repack backup (refresh zpaq files for minimize):"
echo
"
$
eterbackup repack /path/from /path/to"
echo
echo
"Extract backup:"
echo
"
$
eterbackup extract /path/backup /path/to"
exit
;;
*
)
echo
"
$DESCR
"
>
&2
echo
"Run with -h or --help for help"
>
&2
exit
1
;;
esac
# Можно извлечь в новый архив
# zpaq extract -to out.zpaq
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment