{"id":282999,"date":"2016-12-25T15:30:04","date_gmt":"2016-12-25T12:30:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=282999"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=282999","title":{"rendered":"\u0411\u044d\u043a\u0430\u043f \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u0448\u0430\u0440\u044b (samba) \u0432 Linux \u043f\u043e \u043c\u043e\u0442\u0438\u0432\u0430\u043c Windows Server Backup"},"content":{"rendered":"<p>\u0414\u0435\u043b\u0430\u0435\u043c \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0430\u0440\u0445\u0438\u0432\u0430\u043c (\u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u044d\u0442\u0438 \u0430\u0440\u0445\u0438\u0432\u044b) \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0448\u0430\u0440, \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0445 \u043f\u043e\u0434 Windows.<br \/>  <a name=\"habracut\"><\/a><\/p>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u0427\u0435\u043c \u0445\u043e\u0440\u043e\u0448\u0430 \u0441\u043b\u0443\u0436\u0431\u0430 Windows Server Backup \u0438 \u0442\u0435\u043d\u0435\u0432\u044b\u0435 \u043a\u043e\u043f\u0438\u0438? \u041e\u043d\u0438 \u0432\u0445\u043e\u0434\u044f\u0442 \u0432 \u043f\u043e\u0441\u0442\u0430\u0432\u043a\u0443 Windows Server \u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0434\u043e\u043f\u043b\u0430\u0442\u044b (\u0435\u0441\u043b\u0438 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u043b\u0430\u0447\u043d\u0443\u044e \u0430\u0440\u0445\u0438\u0432\u0430\u0446\u0438\u044e), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u0432\u043e\u0437\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c\u0438 \u043d\u0430 \u043d\u0438\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u043e\u0447\u0435\u043d\u044c \u0434\u043e\u0441\u0442\u043e\u0439\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u0410 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0442\u0435\u043d\u0435\u0432\u044b\u043c \u043a\u043e\u043f\u0438\u044f\u043c \u0447\u0435\u0440\u0435\u0437 \u0434\u0438\u0430\u043b\u043e\u0433 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0444\u0430\u0439\u043b\u0430 \u2014 \u0432\u043e\u043e\u0431\u0449\u0435 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u0435\u043d. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0434\u043b\u044f \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430 Linux \u0441 Samba.<\/p>\n<h3>\u0414\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c \u0432\u0435\u0440\u0441\u0438\u044f\u043c \u0444\u0430\u0439\u043b\u043e\u0432<\/h3>\n<p>  \u042d\u0442\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u043c \u0434\u0430\u0435\u0442 \u043c\u043e\u0434\u0443\u043b\u044c Samba shadow_copy2.<br \/>  \u0415\u0433\u043e \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432 \u0441\u0435\u043a\u0446\u0438\u0438 \u0441\u0435\u0442\u0435\u0432\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430 \u0432 \u0444\u0430\u0439\u043b\u0435 smb.conf  <\/p>\n<pre><code class=\"bash\">[share] vfs objects = shadow_copy2 shadow:snapdir = \/mnt\/.share path = \/mnt\/share <\/code><\/pre>\n<p>  \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043c\u043e\u0434\u0443\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438, \u044d\u0442\u043e\u0442 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043f\u0430\u043f\u043a\u0443 \u0441 \u043a\u043e\u043f\u0438\u044f\u043c\u0438 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u0438 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0438\u043c\u0435\u043d\u0430\u043c\u0438.<br \/>  \u0422\u0435\u043f\u0435\u0440\u044c, \u0435\u0441\u043b\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0430\u043f\u043a\u0438 path = \/mnt\/.share \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u043e\u0434\u043f\u0430\u043f\u043a\u0443 @GMT-2016.12.25-10.17.52<br \/>  \u0442\u043e \u0443 \u043d\u0430\u0441 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u044b\u0439\u0434\u0435\u0442. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0430\u043a\u0438\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0432 \u0441\u0435\u043a\u0446\u0438\u0438 [general]  <\/p>\n<pre><code class=\"bash\">   wide links = yes # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c samba \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u044c\u043d\u044b\u043c \u0441\u0441\u044b\u043b\u043a\u0430\u043c    unix extensions = no # \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u043c *nix \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0441\u0441\u044b\u043b\u043e\u043a (\u0438 \u0435\u0449\u0435 \u043a\u0443\u0447\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439, # \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0430\u043c \u043c\u043e\u0433\u0443\u0442 \u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f)    allow insecure wide links = no # \u044d\u0442\u0443 \u043e\u043f\u0446\u0438\u044e \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0432 yes \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445 unix extensions # \u0438\u043d\u0430\u0447\u0435 wide links \u043e\u0441\u0442\u0430\u043d\u0443\u0442\u0441\u044f \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b, \u0438 \u0434\u044b\u0440\u044b \u0432 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u0448\u0430\u0440\u044b, \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u0439, \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u043d\u0430\u0448\u0443 \u00ab\u043a\u043e\u043f\u0438\u044e\u00bb. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0432\u0440\u0435\u043c\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 UTC \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e \u0447\u0430\u0441\u043e\u0432\u043e\u043c\u0443 \u043f\u043e\u044f\u0441\u0443.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0430\u0440\u0445\u0438\u0432\u043e\u0432 \u0438 snapshot<\/h3>\n<p>  \u0418\u043c\u0435\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043a\u043e\u043f\u0438\u044f\u043c \u0431\u0435\u0437 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u2014 \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u043e. \u0412 \u044d\u0442\u043e\u043c \u043d\u0430\u043c \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u043a\u0440\u0438\u043f\u0442:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">thin_lv_backup.sh<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/bash # #     LVM-ThinVolume BackUp with rsync script set # #     (c) 2016 - #         Andrew Leshkevich (magicgts@gmail.com) # # #\tThis script set is free software; you can redistribute it and\/or modify #\tit under the terms of the GNU General Public License as published by the #       Free Software Foundation, either version 2 of the license or, at your #       option, any later version. # #\tThis program is distributed in the hope that it will be useful, #\tbut WITHOUT ANY WARRANTY; without even the implied warranty of #\tMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #\tGNU General Public License for more details. # #\tYou should have received a copy of the GNU General Public License #\talong with this program; if not, see &lt;http:\/\/www.gnu.org\/licenses\/&gt;. # #       For a list of supported commands, type 'thin_lv_backup help' # #\t!!!\tPlease forgive me for bad english\t!!! # ################################################################################################  ################################################################################################ #Mount the snapshot to the specified mount point, if a snapshot is not active, then activate it # Arguments: #   ${1} - Short path to Volume (in VG\/LV format) #   ${2} - Mount point #   ${3} - Optional LMV Volume attribute # Returns: #   Return 0 if no errors ################################################################################################ mount_snapshot(){ \tlocal SRC=${1} \tlocal MNT_TGT=${2} \t[ &quot;$#&quot; -lt 2 ] && echo 'Error: expected &lt;VOLUME GROUP&gt;\/&lt;LOGICAL VOLUME SNAPSHOT&gt; &lt;MOUNT POINT&gt; [&lt;VOLUME ATTRIBUTES&gt;]' && return 1 \tif [ &quot;$#&quot; -eq 2 ]; then  \t\tlocal ATTR=$(lvs --noheadings -o lv_attr ${SRC}) \telse \t\tlocal ATTR=${3} \tfi \tfindmnt -nf --source \/dev\/${SRC} &gt;\/dev\/null 2&gt;&1 && echo &quot;Skip: LV ${SRC} is already mounted!&quot; && return 0 \tfindmnt -nf --target ${MNT_TGT} &gt;\/dev\/null 2&gt;&1 | grep -v -q ${MNT_TGT} && echo &quot;Skip: the directory ${MNT_TGT} is already a mount point&quot; && return 3 \tif [ ! -d &quot;${MNT_TGT}&quot; ]; then \t\tmkdir -p &quot;${MNT_TGT}&quot; || echo &quot;Error: Creating directory ${MNT_TGT}&quot; || return 4 \t\techo &quot;Info: directory ${MNT_TGT} has been created&quot; \tfi \tfind ${MNT_TGT} -prune -empty | grep -v -q ${MNT_TGT} && echo &quot;Skip: ${MNT_TGT} directory is not empty&quot; && return 5 \t[[ ${ATTR} =~ .*a.* ]] || lvchange -ay -K ${SRC} || echo &quot;Error: Volume Activation ${SRC}&quot; || return 6 \tmount -o ro,nouuid \/dev\/${SRC} ${MNT_TGT} || echo &quot;Error: Mounting ${MNT_TGT}&quot; || return 7 \treturn 0 }  ################################################################################################ # UnMount snaphot, deactivate volume and remove it mount point directory # Arguments: #   ${1} - Short path to Volume (in VG\/LV format) # Returns: #   Return 0 if no errors ################################################################################################ umount_snapshot(){ \tlocal SRC=${1} \tlocal TGT \t[ &quot;$#&quot; -ne 1 ] && echo 'Error: expected &lt;VOLUME GROUP&gt;\/&lt;LOGICAL VOLUME SNAPSHOT&gt;' && return 1 \tlocal _TGT=(&quot;$( findmnt -nf --source \/dev\/${SRC} | cut -d ' ' -f 1 )&quot;) \tif [ ! -z &quot;$_TGT&quot; ]; then \t\tumount -A \/dev\/${SRC} || echo &quot;Error: Umounting ${SRC}&quot; || return 2 \t\tfor TGT in &quot;${_TGT[@]}&quot;; do \t\t\tfind ${TGT} -prune -empty | grep -q &quot;${TGT}&quot; && rm --one-file-system -df ${TGT} \t\t\t[ -d &quot;${TGT}&quot; ] && echo &quot;Info: Fail to remove target directory ${TGT}&quot; \t\tdone \tfi \tlvchange -an -K ${SRC} || echo &quot;Error: Volume Deactivation ${SRC}&quot; || return 3 \treturn 0 }  ################################################################################################ # Mount all associated snapshots of the volume to its origin mount points # All snapshots must be named on the template: &lt;ORIGIN VOLUME NAME&gt;-GMT-%Y.%m.%d-%H.%M.%S # Arguments: #   ${1} - Short path to Origin Volume (in VG\/LV format) #   ${2} - Optional archive volume group, that used to mount all archive snapshots # Returns: #   Return 0 if no errors ################################################################################################ mount_all_snapshot(){ \tlocal SRC=${1} \tlocal A_VG=${2} \tlocal ATTR_S \tlocal SNAP \t[ &quot;$#&quot; -lt 1 ] && echo 'Error: expected &lt;VOLUME GROUP&gt;\/&lt;LOGICAL VOLUME&gt; [&lt;ARCHIVE VOLUME GROUP&gt;]' && exit 1 \tIFS=$'\/' read -r -a ATTR_S &lt;&lt;&lt; &quot;${SRC}&quot; \t[ &quot;$#&quot; -eq 2 ] && ATTR_S[0]=${A_VG} \tlocal SRC=&quot;$( findmnt -nf --source \/dev\/${SRC} | cut -d ' ' -f 1 )\/&quot; \tlocal DST_BASE=&quot;$( dirname ${SRC} )\/.$( basename ${SRC} )\/&quot; \twhile IFS='' read -r SNAP; do \t\tIFS=$' \\t' read -r -a ATTR &lt;&lt;&lt; &quot;${SNAP}&quot; \t\tlocal DST=${ATTR[0]\/\/${ATTR_S[1]}-\/} \t\tmount_snapshot ${ATTR_S[0]}\/${ATTR[0]} ${DST_BASE}@${DST} ${ATTR[1]}  || echo &quot;Error: mounting ${ATTR_S[0]}\/${ATTR[0]}&quot; \tdone &lt; &lt;( lvs --noheadings -o lv_name,lv_attr -S Origin=${ATTR_S[1]} ${ATTR_S[0]} ) }  ################################################################################################ # UnMount and Remove snapshot # Arguments: #   ${1} - Short path to Snapshot Volume (in VG\/LV format) # Returns: #   Return 0 if no errors ################################################################################################ remove_snaphot(){ \tlocal TGT=${1} \tlocal ATTR_S \t[ &quot;$#&quot; -ne 1 ] && echo 'Error: expected &lt;VOLUME GROUP&gt;\/&lt;LOGICAL VOLUME SNAPSHOT&gt;' && return 1 \tIFS=$'\/' read -r -a ATTR_S &lt;&lt;&lt; &quot;${TGT}&quot; \t[ -z $(lvs --noheadings -o Origin -S lv_name=${ATTR_S[1]} ${ATTR_S[0]}) ] && echo &quot;Error: not a snapshot ${TGT}&quot; && return 2 \tumount_snapshot ${TGT} || echo &quot;Error: umounting snapshot ${TGT}&quot; || return 3 \tlvremove -f \/dev\/${TGT} || echo &quot;Error: removing snapshot ${TGT}&quot; || return 4 \treturn 0 }  ################################################################################################ # Create and Mount it to hidden folder on top level with same name as Original mount point # Arguments: #   ${1} - Short path to Origin Volume (in VG\/LV format) #   ${2} - Optional postfix, that replace default postfix GMT-%Y.%m.%d-%H.%M.%S # Returns: #   Return 0 if no errors ################################################################################################ create_snaphot(){ \tlocal TGT=${1} \tlocal ATTR_S \t[ &quot;$#&quot; -lt 1 ] && echo 'Error: expected &lt;VOLUME GROUP&gt;\/&lt;LOGICAL VOLUME&gt; [&lt;POSTFIX&gt;]' && exit 1 \tlocal DATE=$(date -u +GMT-%Y.%m.%d-%H.%M.%S) \t[ &quot;$#&quot; -eq 2 ] && DATE=&quot;${2}&quot; \tIFS=$'\/' read -r -a ATTR_S &lt;&lt;&lt; &quot;${TGT}&quot; \tlvcreate -n ${ATTR_S[1]}-${DATE} -s \/dev\/${TGT} || echo &quot;Error: Creating snapshot of ${TGT}&quot; || return 2 \tlocal SRC=&quot;$( findmnt -nf --source \/dev\/${TGT} | cut -d ' ' -f 1 )\/&quot; \tlocal DST_BASE=&quot;$( dirname $SRC )\/.$( basename $SRC )\/&quot; \tmount_snapshot ${TGT}-${DATE} ${DST_BASE}@${DATE} || echo &quot;Error: Mounting snapshot ${TGT}-${DATE}&quot; || return 3 }  ################################################################################################ # Remove old snaphots and keep last N snapshot # Arguments: #   ${1} - Short path to Origin Volume (in VG\/LV format) #   ${2} - Number of keeping snapshot # Returns: #   Return 0 if no errors ################################################################################################ remove_old_snapshot_copy(){ \tlocal TGT=${1} \tlocal NUM=${2} \tlocal SNAP \tlocal ATTR_S \tlocal ATTR \t[ &quot;$#&quot; -ne 2 ] && echo 'Error: expected &lt;VOLUME GROUP&gt;\/&lt;LOGICAL VOLUME&gt; &lt;NUMBER OF KEEP&gt;' && return 1 \tIFS=$'\/' read -r -a ATTR_S &lt;&lt;&lt; &quot;${TGT}&quot; \twhile IFS='' read -r SNAP; do \t\tIFS=$' \\t' read -r -a ATTR &lt;&lt;&lt; &quot;${SNAP}&quot; \t\tlocal DST=${ATTR[0]\/\/${ATTR_S[1]}-\/} \t\tremove_snaphot ${ATTR_S[0]}\/${ATTR[0]} || echo &quot;Error: removing snapshot ${ATTR_S[0]}\/${ATTR[0]}&quot; \tdone &lt; &lt;( (lvs --noheadings -O -lv_name -o lv_name -S Origin=${ATTR_S[1]} ${ATTR_S[0]}) | head -n -${NUM} ) \treturn 0 }  ################################################################################################ # Prepare archive operation # Arguments: #   ${1} - Short path to Origin Volume (in VG\/LV format) #   ${2} - Mount point for ${1} # Returns: #   Return 0 if no errors ################################################################################################ pre_archive(){ \t[ &quot;$#&quot; -ne 2 ] && echo 'Error: expected &lt;VOLUME GROUP&gt;\/&lt;LOGICAL VOLUME&gt; &lt;MOUNT POINT&gt;' && return 1 \tlocal VOL_SRC=${1} \tlocal MNT_TGT=${2} \tmkdir -p ${MNT_TGT} \tmount \/dev\/${VOL_SRC} ${MNT_TGT} || echo &quot;Error: Mounting ${MNT_TGT}&quot; || return 7 }  ################################################################################################ # Post archive operation: unmount target volume, remove its mount point, create its snaphot # Arguments: #   ${1} - Short path to Origin Volume (in VG\/LV format) #   ${2} - Mount point for ${1} # Returns: #   Return 0 if no errors ################################################################################################ post_archive(){ \t[ &quot;$#&quot; -ne 3 ] && echo 'Error: expected &lt;VOLUME GROUP&gt;\/&lt;LOGICAL VOLUME&gt; &lt;MOUNT POINT&gt; &lt;VOLUME GROUP&gt;\/&lt;LOGICAL VOLUME&gt;' && return 1 \tlocal VOL_SRC=${1} \tlocal MNT_TGT=${2} \tlocal TGT=${3} \tumount \/dev\/${VOL_SRC} && rm -rd ${MNT_TGT} && lvcreate -n ${TGT} -s \/dev\/${VOL_SRC} && return 0 \treturn 1 } ################################################################################################ # Create rsync archive # Arguments: #   ${1} - Short path to Origin Volume (in VG\/LV format) #   ${2} - Name of archive Volume Group #   ${3} - Optional connection string in &lt;user name&gt;@&lt;host name&gt; format #   ${4} - Optional path to this script on remote machine #   ${5} - Optional prefix name for volume name on remote machine (&lt;PREFIX&gt;-&lt;VOLUME NAME&gt;-GMT-%Y.%m.%d-%H.%M.%S) #   ${6} - Optional also make local archive # Returns: #   Return 0 if no errors ################################################################################################ create_archive(){ \tlocal SRC=${1} \tlocal TGT=${2} \tlocal CONN=${3} \tlocal CALL=${4} \tlocal PREFIX=${5} \tlocal ATTR_S \tlocal ATTR_D \tlocal RESULTS \tlocal RET \t[ &quot;$#&quot; -lt 2 ] && echo 'Error: expected &lt;ORIG VOLUME GROUP&gt;\/&lt;ORIG LOGICAL VOLUME&gt; &lt;DST VOLUME GROUP&gt; [&lt;SSH CONNECT&gt; &lt;SCRIPT CALL&gt; &lt;PREFIX&gt; [&lt;LOCAL COPY?&gt;]]' && return 1 \tIFS=$'\/' read -r -a ATTR_S &lt;&lt;&lt; &quot;${SRC}&quot; \tIFS=$'\/' read -r -a ATTR_D &lt;&lt;&lt; &quot;${TGT}&quot; \tlocal SRC=&quot;$( findmnt -nf --source \/dev\/${ATTR_S[0]}\/${ATTR_S[1]} | cut -d ' ' -f 1 )\/&quot; \tlocal DST_BASE=&quot;$( dirname $SRC )\/.$( basename $SRC )\/&quot; \tcreate_snaphot ${ATTR_S[0]}\/${ATTR_S[1]} archive_orig \tlocal DATE=$(date -u +GMT-%Y.%m.%d-%H.%M.%S)\t \tif [ &quot;$#&quot; -ge 5 ]; then \t\tRESULTS=$(ssh ${CONN} &quot;${CALL} pre_archive ${TGT}\/${PREFIX}-${ATTR_S[1]} ${DST_BASE}@archive_dst&quot;) \t\tRET=$? \t\techo &quot;$RESULTS&quot; \t\t[ &quot;${RET}&quot; -ne 0 ] && return ${RET} \t\trsync -aAXx --delete ${DST_BASE}@archive_orig\/ ${CONN}:${DST_BASE}@archive_dst &&\\\t\t \t\tRESULTS=$(ssh ${CONN} &quot;${CALL} post_archive ${TGT}\/${PREFIX}-${ATTR_S[1]} ${DST_BASE}@archive_dst ${PREFIX}-${ATTR_S[1]}-${DATE}&quot;) \t\tRET=$? \t\techo &quot;$RESULTS&quot; \t\t[ &quot;${RET}&quot; -ne 0 ] && return ${RET} \tfi \tif [ &quot;$#&quot; -eq 2 ] || [ &quot;$#&quot; -eq 6 ]; then \t\tpre_archive ${TGT}\/${ATTR_S[1]} ${DST_BASE}@archive_dst \t\trsync -aAXx --delete ${DST_BASE}@archive_orig\/ ${DST_BASE}@archive_dst &&\\ \t\tpost_archive ${TGT}\/${ATTR_S[1]} ${DST_BASE}@archive_dst ${ATTR_S[1]}-${DATE} \t\tRET=$? \t\t[ &quot;${RET}&quot; -ne 0 ] && return ${RET} \t\tmount_snapshot ${TGT}\/${ATTR_S[1]}-${DATE} ${DST_BASE}@${DATE} \telse \t\t echo 'Error: expected &lt;ORIG VOLUME GROUP&gt;\/&lt;ORIG LOGICAL VOLUME&gt; &lt;DST VOLUME GROUP&gt; [&lt;SSH CONNECT&gt; &lt;SCRIPT CALL&gt; &lt;PREFIX&gt; [&lt;LOCAL COPY?&gt;]]&gt;' && return 1 \tfi \tremove_snaphot ${ATTR_S[0]}\/${ATTR_S[1]}-archive_orig } case ${1} in \t\t'help') \t\t\t[ -z &quot;${2}&quot; ] && echo -e &quot;create - create snapshot and mount it\\nmount - mount snapshot\\numount unmount snapshot\\nmount_all - mount all snapshot\\n\\ remove - remove snapshot\\nremove_old - keep last n snapshot\\ncreate_archive - create archive&quot; \t\t\tcase ${2} in \t\t\t\t'create') \t\t\t\t\techo 'thin_lv_backup.sh create &lt;VOLUME GROUP&gt;\/&lt;LOGICAL VOLUME&gt; [&lt;POSTFIX&gt;]' \t\t\t\t;; \t\t\t\t'mount') \t\t\t\t\techo 'thin_lv_backup.sh mount &lt;VOLUME GROUP&gt;\/&lt;LOGICAL VOLUME SNAPSHOT&gt; &lt;MOUNT POINT&gt; [&lt;VOLUME ATTRIBUTES&gt;]' \t\t\t\t;; \t\t\t\t'umount') \t\t\t\t\techo 'thin_lv_backup.sh umount &lt;VOLUME GROUP&gt;\/&lt;LOGICAL VOLUME SNAPSHOT&gt;' \t\t\t\t;; \t\t\t\t'mount_all') \t\t\t\t\techo 'thin_lv_backup.sh mount_all &lt;VOLUME GROUP&gt;\/&lt;LOGICAL VOLUME&gt; [&lt;ARCHIVE VOLUME GROUP&gt;]' \t\t\t\t;; \t\t\t\t'remove') \t\t\t\t\techo 'thin_lv_backup.sh remove &lt;VOLUME GROUP&gt;\/&lt;LOGICAL VOLUME SNAPSHOT&gt;' \t\t\t\t;; \t\t\t\t'remove_old') \t\t\t\t\techo 'thin_lv_backup.sh remove_old &lt;VOLUME GROUP&gt;\/&lt;LOGICAL VOLUME&gt; &lt;NUMBER OF KEEP&gt;' \t\t\t\t;; \t\t\t\t'create_archive') \t\t\t\t\techo 'thin_lv_backup.sh create_archive &lt;ORIG VOLUME GROUP&gt;\/&lt;ORIG LOGICAL VOLUME&gt; &lt;DST VOLUME GROUP&gt; [&lt;SSH CONNECT&gt; &lt;SCRIPT CALL&gt; &lt;PREFIX&gt; [&lt;LOCAL COPY?&gt;]]' \t\t\t\t;; \t\t\tesac \t\t;; \t\t'create') \t\t\tcreate_snaphot $2 $3 \t\t;; \t\t'mount') \t\t\tmount_snapshot $2 $3 $4 \t\t;; \t\t'umount') \t\t\tumount_snapshot $2 \t\t;; \t\t'mount_all') \t\t\tmount_all_snapshot $2 $3 \t\t;; \t\t'remove') \t\t\tremove_snaphot $2 \t\t;; \t\t'remove_old') \t\t\tremove_old_snapshot_copy $2 $3 \t\t;; \t\t'create_archive') \t\t\tcreate_archive $2 $3 $4 $5 $6 $7 \t\t;; \t\t'pre_archive') \t\t\tpre_archive $2 $3 \t\t;; \t\t'post_archive') \t\t\tpost_archive $2 $3 $4 \t\t;; esac <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">disclaimer<\/b><\/p>\n<div class=\"spoiler_text\">\u0421\u043a\u0440\u0438\u043f\u0442 \u043d\u0435 \u0438\u0434\u0435\u0430\u043b\u0435\u043d (\u043f\u043e\u043a\u0430 \u044f \u043d\u0430\u0431\u0438\u0432\u0430\u044e \u0440\u0443\u043a\u0443) \u0438 \u043e\u043f\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u0430\u0448\u0443 \u0434\u043e\u0431\u0440\u043e\u0441\u043e\u0432\u0435\u0441\u0442\u043d\u043e\u0441\u0442\u044c (\u043d\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e). \u041e\u0434\u043d\u0430\u043a\u043e, \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u044b\u0445 (\u043e\u043d \u043d\u0435 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u0442\u043e\u043c\u0430, \u0442\u043e\u043b\u044c\u043a\u043e snapshot, \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0443\u0441\u0442\u044b\u0435 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0438). \u0412\u0430\u0448\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u043e \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044e \u0438 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e, \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442\u0441\u044f.  <\/div>\n<\/div>\n<p>  \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c LVM ThinVolumes. \u041f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u0442\u043e\u043c\u0430\u043c\u0438, \u0438\u0445 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043b\u0430\u0431\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0447\u0438\u0441\u043b\u0430 snapshot (COW \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432 2-3 \u0440\u0430\u0437\u0430, \u043f\u043e\u043a\u0430 \u0432\u044b \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442\u0435 \u00ab\u0441\u0432\u0435\u0436\u0438\u0435\u00bb \u0431\u043b\u043e\u043a\u0438, \u0430 \u0435\u0441\u043b\u0438 \u0441\u043d\u0438\u043c\u043a\u043e\u0432 2 \u0438 \u0431\u043e\u043b\u0435\u0435, \u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043c\u0438\u0440\u0430\u0435\u0442).<\/p>\n<p>  \u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0430\u0440\u0445\u0438\u0432\u043d\u044b\u0445 \u043a\u043e\u043f\u0438\u0439:<\/p>\n<ol>\n<li>\u0421\u043e\u0437\u0434\u0430\u0442\u044c snapshot \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0442\u043e\u043c\u0430 \u0438 \u0441\u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e<\/li>\n<li>\u0421\u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043c \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/li>\n<li>\u041f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e rsync<\/li>\n<li>\u041e\u0442\u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043c \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e snaphot<\/li>\n<li>\u041e\u0442\u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c snapshot \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0435\u0433\u043e<\/li>\n<li>\u041f\u0440\u0438 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u0430\u0440\u0445\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, \u043f\u043e\u0434\u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 snapshot \u0442\u043e\u043c\u0430 \u0441 \u0430\u0440\u0445\u0438\u0432\u043e\u043c<\/li>\n<\/ol>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u043d\u044b\u0439 \u0431\u044d\u043a\u0430\u043f. \u041f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438, \u043c\u043e\u0436\u043d\u043e \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f btrfs \u0438\u043b\u0438 ZFS.<\/p>\n<h3>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/h3>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0442\u044c snapshot \u0438 \u043f\u0440\u0438\u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0441\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c \u0448\u0430\u0440\u044b (\u043f\u0430\u043f\u043a\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0439 \u0448\u0430\u0440\u0443):  <\/p>\n<pre><code class=\"bash\">\/usr\/local\/bin\/thin_lv_backup.sh create vg_system\/share<\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u0440\u0445\u0438\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e rsync \u043d\u0430 \u0434\u0440\u0443\u0433\u0443\u044e \u0433\u0440\u0443\u043f\u043f\u0443 \u0442\u043e\u043c\u043e\u0432:  <\/p>\n<pre><code class=\"bash\">\/usr\/local\/bin\/thin_lv_backup.sh create_archive vg_system\/share vg_archive<\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0439 \u0430\u0440\u0445\u0438\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e rsync:  <\/p>\n<pre><code class=\"bash\">\/usr\/local\/bin\/thin_lv_backup.sh create_archive vg_system\/share vg_archive archive@archive.localdomain 'sudo \/usr\/local\/bin\/thin_lv_backup.sh' srv1<\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0439 \u0438 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b \u0430\u0440\u0445\u0438\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e rsync:  <\/p>\n<pre><code class=\"bash\">\/usr\/local\/bin\/thin_lv_backup.sh create_archive vg_system\/share vg_archive archive@archive.localdomain 'sudo \/usr\/local\/bin\/thin_lv_backup.sh' srv1 true<\/code><\/pre>\n<p>  \u0423\u0434\u0430\u043b\u0438\u0442\u044c \u0441\u0442\u0430\u0440\u044b\u0435 \u043a\u043e\u043f\u0438\u0438 (\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c N \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445)  <\/p>\n<pre><code class=\"bash\">\/usr\/local\/bin\/thin_lv_backup.sh remove_old vg_system\/share 5<\/code><\/pre>\n<p>  \u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0441\u043f\u0440\u0430\u0432\u043a\u0430:  <\/p>\n<pre><code class=\"bash\">\/usr\/local\/bin\/thin_lv_backup.sh help<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">\/usr\/local\/bin\/thin_lv_backup.sh help mount_all<\/code><\/pre>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/318388\/\"> https:\/\/habrahabr.ru\/post\/318388\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0414\u0435\u043b\u0430\u0435\u043c \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0430\u0440\u0445\u0438\u0432\u0430\u043c (\u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u044d\u0442\u0438 \u0430\u0440\u0445\u0438\u0432\u044b) \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0448\u0430\u0440, \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0445 \u043f\u043e\u0434 Windows.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-282999","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/282999","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=282999"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/282999\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=282999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=282999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=282999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}