diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2012-12-25 11:31:28 -0200 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2012-12-25 11:31:28 -0200 |
commit | baf30b586919d52da095e9224f5dbe35b619377a (patch) | |
tree | 2e8d57c46095015ebecd079f7e3294a738ddcaac | |
parent | 936d9e030bead996486164abce45c0a16183222e (diff) | |
download | puppet-backup-baf30b586919d52da095e9224f5dbe35b619377a.tar.gz puppet-backup-baf30b586919d52da095e9224f5dbe35b619377a.tar.bz2 |
Adding sync-media script
-rwxr-xr-x | files/sync-media | 113 | ||||
-rw-r--r-- | manifests/init.pp | 9 |
2 files changed, 122 insertions, 0 deletions
diff --git a/files/sync-media b/files/sync-media new file mode 100755 index 0000000..f80f1e8 --- /dev/null +++ b/files/sync-media @@ -0,0 +1,113 @@ +#!/bin/bash +# +# sync-media assets using git-annex +# + +VOLUME="/media/usb" +CACHE="/var/cache/media" +DOMAIN="`facter domain`" +MEDIA="media.$DOMAIN" +INCOMING="$CACHE/incoming" +WHOAMI="`whoami`" + +# Set sudo config +if [ "$WHOAMI" != 'root' ]; then + sudo="sudo" +fi + +# Commit changes +if [ -d "$CACHE" ]; then + # Fix cache permissions + #echo "Fixing $CACHE permissions..." + #$sudo find $CACHE -type f -exec chmod 644 {} \; + #$sudo find $CACHE -type d -exec chmod 755 {} \; + + # Fix incoming permissions + if [ -d "$INCOMING" ]; then + echo "Fixing $INCOMING permissions..." + $sudo find $INCOMING -type f -exec chmod 664 {} \; + $sudo find $INCOMING -type d -exec chmod 775 {} \; + $sudo chown -R $WHOAMI $INCOMING/* + fi + + # Add and update local repositories + for folder in `ls $CACHE`; do + if [ -d "$CACHE/$folder/.git/annex" ]; then + ( + cd $CACHE/$folder + echo "Syncing $CACHE/$folder..." + git annex add . + + # Adding hidden files and symlinks, find version + #find -name '.*' -exec git annex add {} \; + #find -type l -exec git add {} \; + + # Adding hidden files and symlinks, git+for version + #for file in `git status --porcelain -u | sed -e 's/?? //'`; do + # if [ -h "$file" ]; then + # git add $file + # else + # git annex add $file + # fi + #done + + # Adding hidden files and symlinks, git+while version + git status --porcelain -u | sed -e 's/?? //' | while read file; do + if [ -h "$file" ]; then + git add "$file" + else + git annex add "$file" + fi + done + + git annex sync + git annex fsck --fast + git annex unused + git annex dropunused 1-1000 + ) + fi + done + + # Check storage media + MOUNT="`mount | grep $VOLUME`" + if [ ! -z "$MOUNT" ]; then + DRIVE="$(basename `echo $MOUNT | awk '{ print $1 }'`)" + fi + + if [ ! -z "$DRIVE" ]; then + if [ ! -d "$VOLUME/$MEDIA" ]; then + echo "Folder $VOLUME/$MEDIA does not exist..." + else + for folder in `ls $CACHE`; do + if [ -d "$CACHE/$folder/.git/annex" ]; then + if [ ! -d "$VOLUME/$MEDIA/$folder" ]; then + ( + cd $VOLUME/$MEDIA + echo "Initializing $VOLUME/$MEDIA/$folder..." + git clone $CACHE/$folder && cd $folder && git annex init $DRIVE && \ + cd $CACHE/$folder && git remote add $DRIVE $VOLUME/$MEDIA/$folder + ) + fi + fi + done + fi + fi +fi + +# Retrieve changes at media volumes +if [ -d "$VOLUME/$MEDIA" ]; then + for folder in `ls $VOLUME/$MEDIA`; do + if [ -d "$VOLUME/$MEDIA/$folder/.git/annex" ]; then + ( + cd $VOLUME/$MEDIA/$folder + echo "Syncing $VOLUME/$MEDIA/$folder..." + git annex sync + git annex get --auto --numcopies=3 + git annex fsck --fast + git annex unused + git annex dropunused 1-1000 + #git annex drop --auto --numcopies=2 + ) + fi + done +fi diff --git a/manifests/init.pp b/manifests/init.pp index 3950e7e..7c7c164 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -138,6 +138,15 @@ class backup { source => "puppet://$server/modules/backup/sync-backups", } + # sync-media script + file { "/usr/local/sbin/sync-media": + owner => root, + group => root, + mode => 0755, + ensure => present, + source => "puppet://$server/modules/backup/sync-media", + } + # mount-media script file { "/usr/local/sbin/mount-media": owner => root, |