Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract new backup action out of archive.
- Loading branch information
Showing
2 changed files
with
59 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/bash | ||
############################################################################### | ||
## | ||
# FILE: backup | ||
# PRODUCT: todo.txt-cli-ex | ||
# AUTHOR: Ingo Karkat <ingo@karkat.de> | ||
# DATE CREATED: 13-Apr-2012 | ||
# | ||
############################################################################### | ||
# CONTENTS: | ||
# | ||
# REMARKS: | ||
# | ||
# COPYRIGHT: (C) 2012 Ingo Karkat | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU General Public License. | ||
# See http://www.gnu.org/copyleft/gpl.txt | ||
# | ||
# @(#)backup 001 13-Apr-2012 todo.txt-cli-ex | ||
############################################################################### | ||
|
||
action=$1 | ||
shift | ||
|
||
[ "$action" = "usage" ] && { | ||
echo " $(basename $0)" | ||
echo " Writes a backup copy of todo.txt." | ||
echo "" | ||
exit | ||
} | ||
|
||
# Configuration to place the backups into a different directory. | ||
: ${TODOTXT_BACKUP_DIR="${TODO_DIR}.backup"} | ||
# Use a custom backup script if it exists, fall back on a simple copy to a | ||
# timestamp; do nothing when the command is "none". | ||
: ${TODOTXT_BACKUP_COMMAND:=writebackup} | ||
|
||
|
||
if [ "$TODOTXT_BACKUP_COMMAND" = 'none' ]; then | ||
# Skip backup. | ||
: | ||
elif type -P "$TODOTXT_BACKUP_COMMAND" >/dev/null; then | ||
if [ -d "${TODOTXT_BACKUP_DIR%/}" ]; then | ||
"$TODOTXT_BACKUP_COMMAND" -d "${TODOTXT_BACKUP_DIR%/}" "$TODO_FILE" | ||
else | ||
"$TODOTXT_BACKUP_COMMAND" "$TODO_FILE" | ||
fi | ||
else | ||
readonly timestamp=$(date +%F_%H%M%S) | ||
readonly backupFilename="todo_${timestamp}.bak" | ||
if [ -d "${TODOTXT_BACKUP_DIR%/}" ]; then | ||
cp "$TODO_FILE" "${TODOTXT_BACKUP_DIR%/}/${backupFilename}" && echo "Backed up to ${TODOTXT_BACKUP_DIR%/}/${backupFilename}" | ||
else | ||
cp "$TODO_FILE" "$backupFilename" && echo "Backed up to ${backupFilename}" | ||
fi | ||
fi |