Your IP : 216.73.216.21


Current Path : /pkg/zhost/1.0/bin.old/
Upload File :
Current File : //pkg/zhost/1.0/bin.old/zz-backup

#!/bin/bash

repo=$(echo "$1" | tr -d ' ')

# $0 run all|<repo>
# $0 setup <repo_base>

#  .
#  |-- default
#  |   |-- key_private
#  |   |-- key_public
#  |   |-- init.sh
#  |   |-- before.sh
#  |   |-- after.sh
#  |   |-- fail.sh
#  |   |-- BASE
#  |   |-- EXCLUDES
#  |   |-- HOST
#  |   |-- KEEP_DAYS
#  |   |-- KEEP_WEEKS
#  |   |-- KEEP_MONTHS
#  |   |-- PORT
#  |   `-- USER
#  |-- $repo
#  |   `-- as per default files above
#  `-- $folder
#      |-- default
#      |   `-- as per default files above
#      `-- $repo
#          `-- as per default files above
#
# config read order: default, $repo, $folder/default, $folder/$repo

CFG_ROOT='/etc/attic/repo'
TMP_DIR='/tmp/attic'
ERRORS=0

load_cfg() {

    local cfg_dir=$1

    cd $CFG_ROOT

    for i in BASE EXCLUDES HOST PATHS PORT USER key_private after.sh before.sh fail.sh init.sh; do
	if [ -f "$cfg_dir/$i" ]; then
	    cp "$cfg_dir/$i" "$TMP_DIR"
	fi
    done
}

cfg_ok() {

    # TODO: thorough syntax and path existence checks

    for i in BASE HOST USER key_private; do
	# each of these vars must exist and be set
	[[ ! -f "$TMP_DIR/$i" ]] && return 1
    done

    [[ ! -f "$TMP_DIR/PORT" ]] && echo 22 > "$TMP_DIR/PORT"

    return 0
}

get_cfg() {
    cfg=$1
    head -1 "$TMP_DIR/$cfg"
}

load_repo() {

    local repo=$1

    repo_name="$repo"
    repo_base="$CFG_ROOT"

    if echo "$repo" | grep -q '/'; then
	# example: db/mysql/db001
	repo_base="$(dirname "$repo")" # db/mysql
    fi

    cd $CFG_ROOT
    # load the global default config
    [[ -d 'default' ]] && load_cfg 'default'
    # override the global default config with the local default config
    [[ -d "$repo_base/default" ]] && load_cfg "$repo_base/default"
    # finally override the local config with the repo specific config
    [[ -d "$repo" ]] && load_cfg "$repo"

    if ( cfg_ok ); then
	echo "ssh://$(get_cfg USER)@$(get_cfg HOST):$(get_cfg PORT)/$repo.attic"
	return 0
    fi

    return 1
}

#repo_missing() {
    #attic list $CFG_USER $CFG_HOST
#}

backup_repo() {
    local repo=$1
    repo_uri=$(load_repo $repo)
    if [ $? -ne 0 ]; then
	return 1
    fi
    echo "$repo_uri"
    return 0
}

usage() {
    echo "$0 all|<repo>

where <repo> = path to repo relative to $CFG_ROOT
"

}

rm -rf $TMP_DIR
mkdir -p $TMP_DIR
chown root:root $TMP_DIR
chmod 750 $TMP_DIR

cd $CFG_ROOT

if [ "$repo" == '' ]; then
    usage
elif [ "$repo" == 'all' ]; then
    # only process repos with the file ENABLED within their config dir
    repos_enabled=$(find . -name ENABLED | sed 's/^.\///;s/\/ENABLED//')
    for repo_enabled in $repos_enabled; do
	backup_repo $repo_enabled
    done
elif [ -d "$repo" ]; then
    if [ -f "$repo/ENABLED" ]; then
        backup_repo $repo
    else
        echo "ERROR: $repo backup not enabled"
        exit 1
    fi
else
    echo "ERROR: no such repo in $CFG_ROOT"
    exit 1
fi

# if no repo for an account, create it
#attic init attic@$HOST:$type/$repo

#attic create --stats attic@192.168.169.37:web/web9_w4.attic::wed-`date +%Y%m%d-%H%M` /srv/web/web9 --exclude /srv/web/web9/site/.tmb --exclude /srv/web/web9/site/.quarantine


https://nalibali.org/post-sitemap.xml 2026-11-20T09:00:00+00:00 https://nalibali.org/page-sitemap.xml 2026-11-18T09:24:11+00:00 https://nalibali.org/stories-sitemap.xml 2026-05-05T06:48:38+00:00 https://nalibali.org/stories-sitemap2.xml 2026-05-05T06:48:38+00:00 https://nalibali.org/audio_stories-sitemap.xml 2026-03-27T06:53:13+00:00 https://nalibali.org/story_cards-sitemap.xml 2025-06-06T10:27:48+00:00 https://nalibali.org/story_seeds-sitemap.xml 2025-05-19T07:35:43+00:00 https://nalibali.org/rhymes-sitemap.xml 2025-06-17T07:43:10+00:00 https://nalibali.org/activity_sheets-sitemap.xml 2025-05-16T09:16:43+00:00 https://nalibali.org/printables-sitemap.xml 2025-05-16T09:28:40+00:00 https://nalibali.org/posters_bookmarks-sitemap.xml 2025-05-16T10:20:22+00:00 https://nalibali.org/team_member-sitemap.xml 2025-05-28T09:40:43+00:00 https://nalibali.org/video_stories-sitemap.xml 2025-06-23T08:48:28+00:00 https://nalibali.org/guides-sitemap.xml 2025-06-17T09:38:41+00:00 https://nalibali.org/story_supplements-sitemap.xml 2025-09-16T12:22:20+00:00 https://nalibali.org/vacancies-sitemap.xml 2026-09-17T07:05:01+00:00 https://nalibali.org/category-sitemap.xml 2026-11-20T09:00:00+00:00 https://nalibali.org/post_tag-sitemap.xml 2026-11-06T00:00:00+00:00 https://nalibali.org/test-sitemap.xml 2025-06-13T09:36:28+00:00 https://nalibali.org/story_categories-sitemap.xml 2026-05-05T06:48:38+00:00 https://nalibali.org/activity_sheets_categories-sitemap.xml 2025-05-16T09:16:43+00:00 https://nalibali.org/printables_categories-sitemap.xml 2025-05-16T09:28:40+00:00 https://nalibali.org/posters_bookmarks_categories-sitemap.xml 2025-05-16T10:20:22+00:00 https://nalibali.org/single_audio-sitemap.xml 2026-03-27T06:53:13+00:00 https://nalibali.org/rhyme_categories-sitemap.xml 2025-06-17T07:43:10+00:00 https://nalibali.org/guide_categories-sitemap.xml 2025-06-17T09:38:41+00:00 https://nalibali.org/author-sitemap.xml 2026-01-22T07:26:07+00:00