This script was created to automate daily backups of Yandex.Disk. The script is designed to run on a Raspberry Pi Zero with Raspbian OS, but it can also work on Ubuntu or Debian OS. Scenario of backup:
- Mount Yandex.Disk via webdav protocol and sync files automatically.
- Make a copy of a mounted disk using rsync tool.
- Use git for storing diffs of documents.
- Collect list of changes using git.
- Make git commit of changes.
- Send notification message with changes list.
Here's a guide on how to configure a connection:
-
Open the Terminal on your Raspberry Pi running Raspbian.
-
Install the necessary packages by entering the following command:
sudo apt-get install davfs2
- Once the installation is complete, create a directory where you want to mount the Yandex.Disk by entering the following command:
mkdir ~/yandex-disk
- Edit the davfs2 configuration file by entering the following command:
sudo nano /etc/davfs2/secrets
- Add the Yandex.Disk credentials in the following format:
https://webdav.yandex.ru username password
Replace username with your Yandex username and password with your Yandex password. Create Yandex.Disk special password for external app in Yandex account admin.
-
Save and exit the file by pressing Ctrl + X, then Y, and finally Enter.
-
Now, edit the davfs2 configuration file by entering the following command:
sudo nano /etc/davfs2/davfs2.conf
Uncomment the use_locks line by removing the # at the beginning of the line. Save and exit the file.
- To allow non-root users to mount the Yandex.Disk directory, add your user to the davfs2 group by entering the following command:
sudo usermod -aG davfs2 your_username
Replace your_username with your actual username.
- Next, set the proper permissions for the davfs2 configuration file by entering the following command:
sudo chmod 640 /etc/davfs2/secrets
- Finally, mount the Yandex.Disk directory by entering the following command:
sudo mount -t davfs https://webdav.yandex.ru ~/yandex-disk
You should now be able to access and use your Yandex.Disk files and folders through the ~/yandex-disk directory.
Remember to replace username and password in step 5 with your actual Yandex.Disk credentials.
- Making a new directory for storing a copy of your files:
mkdir ~/yadisk
mkdir ~/yadisk/files
- Clonew this repo inside root of your new directory:
cd ~/yadisk
git clone git@github.com:permyakovaa/yandex_disk_backup.git
- Make variables.sh file:
cp variables.sh.dist variables.sh
- Specify your unique paramaeters:
nano variables.sh
YANDEX_DISK_SOURCE_DIR=your_yandex_disk_source_dir
RSYNC_DESTINATION_DIR=your_andex_disk_destination_dir
TELEGRAM_BOT_SECRET=your_telegram_bot_secret
TELEGRAM_CHAT_ID=your_telegram_chat_id
- Open crontab
crontab -e
- Add a new job for cron that will run every morning at 9 AM:
00 9 * * * $RSYNC_DIRECTORY_DIR/rsync.sh 2>&1 | /usr/bin/logger -t rsync.sh