Skip to content

Instantly share code, notes, and snippets.

@voronkovich
Last active August 29, 2015 14:22
Show Gist options
  • Save voronkovich/0571d325c86b03d97ac2 to your computer and use it in GitHub Desktop.
Save voronkovich/0571d325c86b03d97ac2 to your computer and use it in GitHub Desktop.
Backup to Yandex.Disk using webdav
#!/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