Skip to content

Commit

Permalink
Merge pull request #61 from cytopia/release-1.1
Browse files Browse the repository at this point in the history
Release 1.1
  • Loading branch information
cytopia authored Jan 30, 2021
2 parents 7d43337 + 69d9e75 commit 6f476d2
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 20 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog


## Release v1.1

#### Added
- [#60](https://github.com/cytopia/linux-timemachine/issues/60) Allow remote source
- Allow to specify SSH key (`-i` or `--identity`) for remote connections


## Release v1.0

#### Fixed
Expand Down
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,16 @@ accidentally introduce new or old bugs.
```
$ timemachine -h
Usage: timemachine [-vdp] <source> <dest> -- [rsync opts]
timemachine [-vdp] <source> <host>:<dest> -- [rsync opts]
timemachine [-vdp] <source> <user>@<host>:<dest> -- [rsync opts]
timemachine [-vdp] <source> <ssh-alias>:<dest> -- [rsync opts]
Usage: timemachine [-vd] <source> <dest> -- [rsync opts]
timemachine [-vdpi] <source> <host>:<dest> -- [rsync opts]
timemachine [-vdpi] <source> <user>@<host>:<dest> -- [rsync opts]
timemachine [-vdpi] <source> <ssh-alias>:<dest> -- [rsync opts]
timemachine [-vdpi] <host>:<source> <dest> -- [rsync opts]
timemachine [-vdpi] <user>@<host>:<source> <dest> -- [rsync opts]
timemachine [-vdpi] <ssh-alias>:<source> <dest> -- [rsync opts]
timemachine -V, --version
timemachine -h, --help
Expand All @@ -232,12 +238,13 @@ disable those options via --no-perms --no-owner --no-group --no-times and --copy
Required arguments:
<source> Local source directory
<dest> Local destination directory.
<host>:<dest> SSH host and destination directory on server
<user>@<host>:<dest> SSH user, SSH host and destination directory on server
<ssh-alias>:<dest> SSH alias (defined in ~/.ssh/config) and destination directory on server
<host>:<dest> SSH host and source/destination directory on server
<user>@<host>:<dest> SSH user, SSH host and source/destination directory on server
<ssh-alias>:<dest> SSH alias (defined in ~/.ssh/config) and source/destination directory on server
Options:
-p, --port Specify alternative SSH port for remote backups if it is not 22.
-i, --identity Specify path to SSH key.
-v, --verbose Be verbose.
-d, --debug Be even more verbose.
Expand All @@ -254,6 +261,9 @@ Examples:
timemachine -d /home/user /data -- --progress --verbose
Log to file
timemachine -v /home/user /data > /var/log/timemachine.log 2> /var/log/timemachine.err
Documentation:
View more examples at: https://github.com/cytopia/linux-timemachine
```

### Use with cron
Expand Down
57 changes: 44 additions & 13 deletions timemachine
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ MY_DESC="OSX-like timemachine cli script for Linux and BSD (and even OSX)"
MY_PROJ="https://github.com/cytopia/linux-timemachine"
MY_AUTH="cytopia"
MY_MAIL="[email protected]"
MY_VERS="1.0"
MY_DATE="2020-04-02"
MY_VERS="1.1"
MY_DATE="2021-01-30"

# Default command line arguments
VERBOSE=
PORT=
KEY=

# Default variables
SSH_ARGS="-oStrictHostKeyChecking=no -oLogLevel=QUIET -q"
Expand All @@ -29,38 +30,53 @@ SSH_ARGS="-oStrictHostKeyChecking=no -oLogLevel=QUIET -q"
################################################################################

print_usage() {
echo "Usage: ${MY_NAME} [-vdp] <source> <dest> -- [rsync opts]"
echo " ${MY_NAME} [-vdp] <source> <host>:<dest> -- [rsync opts]"
echo " ${MY_NAME} [-vdp] <source> <user>@<host>:<dest> -- [rsync opts]"
echo " ${MY_NAME} [-vdp] <source> <ssh-alias>:<dest> -- [rsync opts]"
echo "Usage: ${MY_NAME} [-vd] <source> <dest> -- [rsync opts]"
echo

echo " ${MY_NAME} [-vdpi] <source> <host>:<dest> -- [rsync opts]"
echo " ${MY_NAME} [-vdpi] <source> <user>@<host>:<dest> -- [rsync opts]"
echo " ${MY_NAME} [-vdpi] <source> <ssh-alias>:<dest> -- [rsync opts]"
echo

echo " ${MY_NAME} [-vdpi] <host>:<source> <dest> -- [rsync opts]"
echo " ${MY_NAME} [-vdpi] <user>@<host>:<source> <dest> -- [rsync opts]"
echo " ${MY_NAME} [-vdpi] <ssh-alias>:<source> <dest> -- [rsync opts]"
echo

echo " ${MY_NAME} -V, --version"
echo " ${MY_NAME} -h, --help"
echo

echo "This shell script mimics the behavior of OSX's timemachine."
echo "It uses rsync to incrementally back up your data to a different directory or remote server via SSH."
echo "All operations are incremental, atomic and automatically resumable."
echo

echo "By default it uses --recursive --perms --owner --group --times --links."
echo "In case your target filesystem does not support any of those options, you can explicitly"
echo "disable those options via --no-perms --no-owner --no-group --no-times and --copy-links."
echo

echo "Required arguments:"
echo " <source> Local source directory"
echo " <dest> Local destination directory."
echo " <host>:<dest> SSH host and destination directory on server"
echo " <user>@<host>:<dest> SSH user, SSH host and destination directory on server"
echo " <ssh-alias>:<dest> SSH alias (defined in ~/.ssh/config) and destination directory on server"

echo " <host>:<dest> SSH host and source/destination directory on server"
echo " <user>@<host>:<dest> SSH user, SSH host and source/destination directory on server"
echo " <ssh-alias>:<dest> SSH alias (defined in ~/.ssh/config) and source/destination directory on server"
echo

echo "Options:"
echo " -p, --port Specify alternative SSH port for remote backups if it is not 22."
echo " -i, --identity Specify path to SSH key."
echo " -v, --verbose Be verbose."
echo " -d, --debug Be even more verbose."
echo

echo "Misc Options:"
echo " -V, --version Print version information and exit"
echo " -h, --help Show this help screen"
echo

echo "Examples:"
echo " Simply back up one directory recursively"
echo " timemachine /home/user /data"
Expand All @@ -70,6 +86,10 @@ print_usage() {
echo " timemachine -d /home/user /data -- --progress --verbose"
echo " Log to file"
echo " timemachine -v /home/user /data > /var/log/timemachine.log 2> /var/log/timemachine.err"
echo

echo "Documentation:"
echo " View more examples at: ${MY_PROJ}"
}

print_version() {
Expand Down Expand Up @@ -200,7 +220,7 @@ link_directory() {
################################################################################

# Parse input args with getopts
while getopts :vdp:hV-: opt; do
while getopts :vdpi:hV-: opt; do
# ----- long options
if [ "${opt}" = "-" ]; then
opt=${OPTARG}
Expand All @@ -223,6 +243,11 @@ while getopts :vdp:hV-: opt; do
PORT="${1}"
SSH_ARGS="${SSH_ARGS} -p ${PORT}"
;;
i | identityity)
shift
KEY="${1}"
SSH_ARGS="${SSH_ARGS} -i ${KEY}"
;;
v | verbose)
if [ "${VERBOSE}" != "debug" ]; then
VERBOSE="verbose"
Expand Down Expand Up @@ -252,11 +277,17 @@ if [ "${#}" -lt "2" ]; then
exit 1
fi

if [ ! -d "${1}" ] && [ ! -f "${1}" ]; then
if is_remote "${1}"; then
if is_remote "${2}"; then
logerr "Source and Target cannot both be remote locations."
exit 1
fi
fi

if ! dir_exists "${1}"; then
logerr "Source directory does not exist: '${1}'. See -h for help."
exit 1
fi

if ! dir_exists "${2}"; then
logerr "Target directory does not exist: '${2}'. See -h for help."
exit 1
Expand Down

0 comments on commit 6f476d2

Please sign in to comment.