{"id":211917,"date":"2014-02-09T12:20:03","date_gmt":"2014-02-09T08:20:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=211917"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=211917","title":{"rendered":"<span class=\"post_title\">\u0411\u044d\u043a\u0430\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 btrfs \u0438 LVM bash \u0441\u043a\u0440\u0438\u043f\u0442\u0430\u043c\u0438<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/ce0\/59a\/2f0\/ce059a2f04e49e6b79d79c60a9126abd.jpg\" alt=\"image\"\/><\/p>\n<p>  \u0423\u0436\u0435 \u0431\u044b\u043b\u043e \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u043e\u0432 \u043e \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u043c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0434\u043b\u044f \u041e\u0421 Linux. \u041e\u0437\u0430\u0431\u043e\u0442\u0438\u043b\u0441\u044f \u0438 \u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u043e\u0439 \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<br \/>  \u0422\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u044d\u043a\u0430\u043f\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u0440\u0438\u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u0438 LVM \u0442\u043e\u043c\u043e\u0432 (\u0434\u0438\u0441\u043a\u0438 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0430\u0448\u0438\u043d). \u0411\u044b\u043b\u0438 \u043c\u044b\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Bacula, \u0442.\u043a. \u0437\u043d\u0430\u043a\u043e\u043c \u0441 \u043d\u0435\u0439, \u043d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0434\u043e\u043c\u0430 \u0442\u043e\u043b\u044c\u043a\u043e 1 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440 \u043a\u043b\u0438\u0435\u043d\u0442-\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0430-\u0431\u044b \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u0432\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0417\u043d\u0430\u0447\u0438\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c, \u043e\u0431\u0440\u0430\u0437 LVM \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e dd. \u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u0443\u044e \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c (\u0445\u043e\u0442\u044f-\u0431\u044b \u0434\u0430\u043d\u043d\u044b\u0445) \u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043c\u0438\u043d\u0438\u043c\u0443\u043c 14 \u0434\u043d\u0435\u0439. \u041d\u043e \u043f\u043e\u0438\u0441\u043a\u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0445 \u0432\u0441\u0435\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044f\u043c \u043d\u0435 \u0443\u0432\u0435\u043d\u0447\u0430\u043b\u0438\u0441\u044c \u0443\u0441\u043f\u0435\u0445\u043e\u043c. \u0410 \u0437\u043d\u0430\u0447\u0438\u0442 \u0431\u0435\u0440\u0435\u043c \u0432 \u0440\u0443\u043a\u0438 bash \u0438 \u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0439 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0434\u0435\u043b\u044e\u0441\u044c \u0442\u0435\u043c, \u0447\u0442\u043e \u0432\u044b\u0448\u043b\u043e.<br \/>  <a name=\"habracut\"><\/a><br \/>  <i>Disclaimer: \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u043d\u0435 \u0431\u044b\u043b\u043e \u0446\u0435\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043e\u043d\u0441\u0442\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u043b\u0430\u044e\u0442 \u0432\u0441\u0435. \u041d\u0443\u0436\u0435\u043d \u0431\u044b\u043b \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0431\u044d\u043a\u0430\u043f\u0430. \u0411\u0443\u0434\u0443 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u0435\u043d \u0437\u0430 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043d\u0435\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u0443\u0437\u043a\u0438\u0445 \u043c\u0435\u0441\u0442 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 (\u0442\u0435\u0445, \u0433\u0434\u0435 \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438). \u0421\u0442\u0430\u0442\u044c\u044f \u0440\u0430\u0441\u0447\u0438\u0442\u0430\u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0430 \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432 \u0432 Linux, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0449\u0443\u0442 \u0433\u043e\u0442\u043e\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u043d\u0430 \u043b\u0435\u043d\u0442\u044f\u0435\u0432 \ud83d\ude42 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043b\u0435\u043d\u044c \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0430\u043c\u0438\u043c.<\/i><\/p>\n<h5>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f:<\/h5>\n<p>  <\/p>\n<ul>\n<li>\u041e\u0421: Arch Linux<\/li>\n<li>\u041a\u043e\u0440\u043d\u0435\u0432\u0430\u044f \u0444\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 (\/): btrfs, \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435 \u0444\u0430\u0439\u043b\u044b.<\/li>\n<li>\u0420\u0430\u0437\u0434\u0435\u043b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 (\/mnt\/data\/): btrfs.<\/li>\n<li>LVM \u0442\u043e\u043c\u0430 (\/dev\/virt_image_array\/*).<\/li>\n<li>\u0420\u0430\u0437\u0434\u0435\u043b \u0434\u043b\u044f \u0431\u044d\u043a\u0430\u043f\u043e\u0432 (\/mnt\/backup\/: etx4, \u0441\u044e\u0434\u0430 \u0431\u0443\u0434\u0443\u0442 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u044b\u0435 \u043a\u043e\u043f\u0438\u0438.<\/li>\n<li>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0443\u0442\u0438\u043b\u0438\u0442\u044b (\u043a\u0440\u043e\u043c\u0435 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0432 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0434\u0438\u0441\u0442\u0440): rsync, btrfs-progs (\u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f btrfs).<\/li>\n<\/ul>\n<p>  \u0411\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u0440\u0430\u0437 \u0432 \u043d\u0435\u0434\u0435\u043b\u044e \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u0443\u044e \u043a\u043e\u043f\u0438\u044e \u0432\u0441\u0435\u0433\u043e \u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043d\u0430\u043f\u0448\u043e\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u043e\u0432 \u0441 btrfs. \u041c\u043e\u0436\u043d\u043e \u0442\u0430\u043a-\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043d\u0430\u043f\u0448\u043e\u0442\u044b LVM \u0442\u043e\u043c\u043e\u0432, \u043d\u043e \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u043f\u043e\u0442\u0435\u0440\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430 \u043d\u0435\u0434\u0435\u043b\u044e \u043d\u0435 \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0445\u0432\u0430\u0442\u0438\u0442 \u0435\u0436\u0435\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043f\u0438\u0439.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0441\u043a\u0440\u0438\u043f\u0442 \u2116 1, \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043a\u043e\u043f\u0438\u044e \u0444\u0430\u0439\u043b\u043e\u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u0432 \/mnt\/backup\/root\/\u00ab\u043d\u043e\u043c\u0435\u0440 \u0434\u043d\u044f\u00bb\/.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u043a\u0440\u0438\u043f\u0442 \u21161<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/bash set -e echo &quot;Date_start: `date +%Y-%m-%d-%H-%M-%S`&quot;\t\t\t\t\t\t #\u0414\u0430\u0442\u0430 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f \u043b\u043e\u0433\u043e\u0432  ### Vars ### #\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043d\u0435\u0439 \u043e\u0442 \u0442\u043e\u0447\u043a\u0438 \u043e\u0442\u0441\u0447\u0435\u0442\u0430 (1970 \u0433\u043e\u0434) day=$((`date +%s` \/ (60*60*24)))\t\t #\u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0431\u044d\u043a\u0430\u043f\u044b dayexp=21\t #\u0427\u0442\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\t\t\t\t\t path=&quot;\/&quot; \t\t #\u041e\u0442\u043a\u0443\u0434\u0430 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c (\u043f\u0443\u0442\u044c \u0434\u043e \u0441\u043d\u0430\u043f\u0448\u043e\u0442\u0430)\t\t\t\t spath=&quot;\/snapshots\/backup_script\/&quot;\t #\u041a\u0443\u0434\u0430 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\t\t\t\t\t\t dpath=&quot;\/mnt\/backup\/root\/&quot; \t\t\t\t\t\t  ### Delete Old Backups ###\t #\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0430\u0440\u044b\u0435 \u0431\u044d\u043a\u0430\u043f\u044b\t\t\t\t find $dpath -type d 2&gt;\/dev\/null| awk '{FS=&quot;\/&quot;} {print $5}'| sort|uniq | while read ONE_OF_LIST do if [[ &quot;$ONE_OF_LIST&quot; -lt &quot;$day - $dayexp&quot;  ]] && [[ -n &quot;$ONE_OF_LIST&quot; ]] then echo &quot;remove: $dpath$ONE_OF_LIST&quot; rm -rf $dpath$ONE_OF_LIST fi done  ### Check exist snapshot ### #\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0441\u043d\u0430\u043f\u0448\u043e\u0442\u0430, \u0443\u0434\u0430\u043b\u044f\u0435\u043c, \u0435\u0441\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u043c\t\t\t\t\t\t if (( &quot;`btrfs subvolume list \/ | grep backup_script |wc -l`&quot; &gt; 0 )) then echo &quot;Warning: Snapshot exist, deleting&quot; btrfs subvolume delete $spath fi  ### Create snapshot ### #\u0414\u0435\u043b\u0430\u0435\u043c \u0441\u043d\u0430\u043f\u0448\u043e\u0442\t\t\t\t\t\t btrfs subvolume snapshot \/ $spath  ### Rsync ###\t\t\t\t\t\t #\u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0441\u043d\u0430\u043f\u0448\u043e\u0442\u0430 rsync -aAXv $spath $dpath$day  ### Delete snapshot ###\t\t\t\t\t\t #\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u043d\u0430\u043f\u0448\u043e\u0442 btrfs subvolume delete $spath echo &quot;Backup succesful complete&quot; echo &quot;Date_end: `date +%Y-%m-%d-%H-%M-%S`&quot; exit 0 <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u043a\u0440\u0438\u043f\u0442 \u2116 2, \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0441\u043d\u0430\u043f\u0448\u043e\u0442\u044b \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0424\u0421 (\u0441\u043a\u0440\u0438\u043f\u0442 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 1\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u044f). \u0421\u043d\u0430\u043f\u0448\u043e\u0442 \u0438\u043c\u0435\u0435\u0442 \u0438\u043c\u044f auto_\u00ab\u043d\u043e\u043c\u0435\u0440 \u0434\u043d\u044f\u00bb.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u043a\u0440\u0438\u043f\u0442 \u21162<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/bash set -e echo &quot;Date_start: `date +%Y-%m-%d-%H-%M-%S`&quot;  ### Vars ### day=$((`date +%s` \/ (60*60*24))) dayexp=14\t\t\t\t\t\t\t\t path=&quot;\/&quot; \t\t\t\t\t\t\t\t spath=&quot;\/snapshots\/&quot;\t\t\t\t\t\t\t  ### Delete Old Backups \/ Check existing snapshot ### #\u0421\u0442\u0430\u0440\u044b\u0435 \u0431\u044d\u043a\u0430\u043f\u044b \u0443\u0434\u0430\u043b\u044f\u0435\u043c, \u0435\u0441\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0441\u043d\u0430\u043f\u0448\u043e\u0442 \u0432\u044b\u0445\u043e\u0434\u0438\u043c  btrfs subvolume list \/ |grep auto |sed -e '1,$ s\/.*_\/\/g'| while read ONE_OF_LIST do if [[ &quot;$ONE_OF_LIST&quot; -lt &quot;$day - $dayexp&quot;  ]] then echo &quot;remove: $spath&quot;auto_&quot;$ONE_OF_LIST&quot; btrfs subvolume delete $spath&quot;auto_&quot;$ONE_OF_LIST fi if [[ &quot;$ONE_OF_LIST&quot; -eq &quot;$day&quot; ]] then echo &quot;Eroor: snapshot auto_$ONE_OF_LIST exist. Stop script execution.&quot; exit 1 fi done  ### Create snapshot ### btrfs subvolume snapshot \/ $spath&quot;auto_&quot;$day  ### End ### echo &quot;Snapshot succesful created&quot; echo &quot;Date_end: `date +%Y-%m-%d-%H-%M-%S`&quot; exit 0 <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u043a\u0440\u0438\u043f\u0442 \u2116 3, \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043a\u043e\u043f\u0438\u044e LVM \u0442\u043e\u043c\u0430:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u043a\u0440\u0438\u043f\u0442 \u21163<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/bash set -e echo &quot;Date_start: `date +%Y-%m-%d-%H-%M-%S`&quot;  ### Vars ### day=$((`date +%s` \/ (60*60*24))) dayexp=21 #\u0418\u043c\u044f \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e LVM \u0442\u043e\u043c\u0430\t\t\t\t\t\t\t\t path=&quot;\/dev\/virt_image_array\/win_home_system&quot; \t\t\t\t spath=&quot;\/dev\/virt_image_array\/backup_lvm1&quot;\t      \t\t\t dpath=&quot;\/mnt\/backup\/lvm1\/&quot;\t\t\t\t\t  ### Delete Old Backups ### find $dpath -type d 2&gt;\/dev\/null| awk '{FS=&quot;\/&quot;} {print $5}'| sort|uniq | while read ONE_OF_LIST do if [[ &quot;$ONE_OF_LIST&quot; -lt &quot;$day - $dayexp&quot;  ]] && [[ -n &quot;$ONE_OF_LIST&quot; ]] then echo &quot;remove: $dpath$ONE_OF_LIST&quot; rm -rf $dpath$ONE_OF_LIST fi done  ### Check exist snapshot ### #\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043e\u0442\u0441\u0443\u0442\u0432\u0438\u0435 \u0441\u043d\u0430\u043f\u0448\u043e\u0442\u0430, \u0443\u0434\u0430\u043b\u044f\u0435\u043c, \u0435\u0441\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u043c if (( &quot;`ls \/dev\/virt_image_array |grep backup_lvm1|wc -l`&quot; &gt; 0 )) then echo &quot;Warning: Snapshot exist, deleting&quot; lvremove --autobackup y -f $spath fi  ### Create snapshot ### #\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043d\u0430\u043f\u0448\u043e\u0442, \u0435\u0441\u043b\u0438 \u043d\u0430 \u0442\u043e\u043c \u0438\u0434\u0435\u0442 \u0430\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u043c\u0435\u0441\u0442\u043e \u043d\u0430 \u0441\u043d\u0430\u043f\u0448\u043e\u0442\u0435. \u042f \u0441\u0434\u0435\u043b\u0430\u043b 10 Gb. lvcreate --size 10G --snapshot --name backup_lvm1 \/dev\/virt_image_array\/win_home_system #\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u043d\u0430\u043f\u0448\u043e\u0442\u0430 \u0441\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u043d\u0430 \u0432\u0430\u0439\u043f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 echo #echo &quot;y&quot;| lvcreate --size 10G -A y --snapshot --name backup_lvm1 \/dev\/virt_image_array\/win_home_system  ### DD ### #\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f \u0441 bs, \u0443 \u043c\u0435\u043d\u044f \u0431\u044b\u0441\u0442\u0440\u0435\u0439 \u0432\u0441\u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 16M dd if=$spath of=$dpath$day bs=16M  ### Delete snapshot ### lvremove --autobackup y -f $spath  echo &quot;Backup succesful complete&quot; echo &quot;Date_end: `date +%Y-%m-%d-%H-%M-%S`&quot; exit 0 <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u043a\u0440\u0438\u043f\u0442\u044b, \u0431\u044d\u043a\u0430\u043f\u044f\u0449\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \/mnt\/data \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430\u043c 1 \u0438 2 \u0434\u0443\u043c\u0430\u044e \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0445 \u043f\u0438\u0441\u0430\u0442\u044c.<\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 crontab \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c, \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u044d\u043a\u0430\u043f\u044b (\u0432 \u043c\u043e\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0431\u044d\u043a\u0430\u043f \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0437 \u0432 \u043d\u0435\u0434\u0435\u043b\u044e, \u0441\u043d\u0430\u043f\u0448\u043e\u0442\u044b \u0440\u0430\u0437 \u0432 \u0434\u0435\u043d\u044c).  <\/p>\n<pre><code class=\"bash\">20 01 * * 1 \/usr\/bin\/backup_root.sh &gt;&gt; \/var\/log\/backup_root.log 2&gt;&1 50 01 * * 1 \/usr\/bin\/backup_lvm1.sh &gt;&gt; \/var\/log\/backup_lvm.log 2&gt;&1 20 01 * * * \/usr\/bin\/snapshot_root.sh &gt;&gt; \/var\/log\/snapshot_root.log 2&gt;&1 <\/code><\/pre>\n<h5>\u0427\u0442\u043e \u0435\u0449\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u0442\u044c:<\/h5>\n<p>  <\/p>\n<ul>\n<li>\u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0431\u044d\u043a\u0430\u043f\u043e\u0432, \u0430 \u043c\u0435\u0441\u0442\u0430 \u043d\u0435\u0442, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0424\u0421 \u0441 \u0434\u0435\u0434\u0443\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0435\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 Opendedup), \u043d\u043e \u0441\u043d\u0438\u0437\u0438\u0442\u0441\u044f \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445.<\/li>\n<li>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043f\u0430\u043f\u043a\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u0430\u044f \u043f\u043e NFS \u0438\u043b\u0438 sshfs.<\/li>\n<li>\u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u044d\u043a\u0430\u043f\u044b \u0438\u043b\u0438 \u0441\u043d\u0430\u043f\u0448\u043e\u0442\u044b \u0447\u0430\u0449\u0435, \u0447\u0435\u043c \u0440\u0430\u0437 \u0432 \u0434\u0435\u043d\u044c \u043c\u043e\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0435 \u0434\u043d\u0438 \u0441 1970 \u0433\u043e\u0434\u0430, \u0430 \u0447\u0430\u0441\u044b (\u043a\u043e\u0441\u0442\u044b\u043b\u044c, \u0431\u0443\u0434\u0435\u0442 \u0435\u0449\u0435 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0439 \u0437\u0430 \u043a\u0430\u043a\u0443\u044e \u0434\u0430\u0442\u0443 \u0431\u044d\u043a\u0430\u043f).<\/li>\n<\/ul>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\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=\"http:\/\/habrahabr.ru\/post\/211917\/\"> http:\/\/habrahabr.ru\/post\/211917\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/ce0\/59a\/2f0\/ce059a2f04e49e6b79d79c60a9126abd.jpg\" alt=\"image\"\/><\/p>\n<p>  \u0423\u0436\u0435 \u0431\u044b\u043b\u043e \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u043e\u0432 \u043e \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u043c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0434\u043b\u044f \u041e\u0421 Linux. \u041e\u0437\u0430\u0431\u043e\u0442\u0438\u043b\u0441\u044f \u0438 \u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u043e\u0439 \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<br \/>  \u0422\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u044d\u043a\u0430\u043f\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u0440\u0438\u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u0438 LVM \u0442\u043e\u043c\u043e\u0432 (\u0434\u0438\u0441\u043a\u0438 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0430\u0448\u0438\u043d). \u0411\u044b\u043b\u0438 \u043c\u044b\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Bacula, \u0442.\u043a. \u0437\u043d\u0430\u043a\u043e\u043c \u0441 \u043d\u0435\u0439, \u043d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0434\u043e\u043c\u0430 \u0442\u043e\u043b\u044c\u043a\u043e 1 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440 \u043a\u043b\u0438\u0435\u043d\u0442-\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0430-\u0431\u044b \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u0432\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0417\u043d\u0430\u0447\u0438\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c, \u043e\u0431\u0440\u0430\u0437 LVM \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e dd. \u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u0443\u044e \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c (\u0445\u043e\u0442\u044f-\u0431\u044b \u0434\u0430\u043d\u043d\u044b\u0445) \u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043c\u0438\u043d\u0438\u043c\u0443\u043c 14 \u0434\u043d\u0435\u0439. \u041d\u043e \u043f\u043e\u0438\u0441\u043a\u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0445 \u0432\u0441\u0435\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044f\u043c \u043d\u0435 \u0443\u0432\u0435\u043d\u0447\u0430\u043b\u0438\u0441\u044c \u0443\u0441\u043f\u0435\u0445\u043e\u043c. \u0410 \u0437\u043d\u0430\u0447\u0438\u0442 \u0431\u0435\u0440\u0435\u043c \u0432 \u0440\u0443\u043a\u0438 bash \u0438 \u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0439 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0434\u0435\u043b\u044e\u0441\u044c \u0442\u0435\u043c, \u0447\u0442\u043e \u0432\u044b\u0448\u043b\u043e.  <\/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-211917","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/211917","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=211917"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/211917\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=211917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=211917"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=211917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}