Last active
August 29, 2015 14:22
-
-
Save voronkovich/0571d325c86b03d97ac2 to your computer and use it in GitHub Desktop.
Backup to Yandex.Disk using webdav
This file contains hidden or 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
#!/usr/bin/env sh | |
remote_url='https://webdav.yandex.ru/backups' | |
credentials=$(cat ~/.yapwd) # user:password | |
curl_command="curl -u $credentials" | |
create_remote_dir() { | |
$curl_command -X MKCOL "$remote_url/$1" | |
return $? | |
} | |
upload_file() { | |
$curl_command -T $1 "$remote_url/${2:-$(basename $1)}" | |
return $? | |
} | |
upload_dir() { | |
abspath=$(realpath -s "$1") | |
dirname=$(basename "$abspath") | |
if create_remote_dir "$dirname"; then | |
for file in $(ls -1 "$abspath"); do | |
# Copy only regular files | |
[ -f "$abspath/$file" ] && upload_file "$abspath/$file" "$dirname/$file" && echo "$file: OK" | |
done | |
fi | |
} | |
upload_dir "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment