1. 程式人生 > >檔案自動備份和同步bypy和syncthing

檔案自動備份和同步bypy和syncthing

Linux定時備份資料到百度雲盤

sudo pip3 install requests
sudo pip3 install bypy

備份指令碼示例

#!/bin/sh
# File:    ~/bysync.sh
# Author:  pipi
# Email: [email protected]

echo -e "\033[33;1m ***********自定義DIRS=~/SysReinstall ~/files/DESKTOP********* \033[0m"
DIRS=$(echo '~/SysReinstall ~/files/DESKTOP')


echo -e "\033[33;1m ************************************ \033[0m"
echo -e "\033[33;1m ************百度雲盤自動同步************ \033[0m"
DATE=`date +%F`
DATE_YEAR=`date +%Y`
DATE_MONTH=`date +%m`
for DIR in $DIRS
do
    echo -e "\033[33;1m *****上傳$(basename $DIR)****** \033[0m"
    bypy mkdir $DATE_YEAR/$DATE_MONTH/$(basename $DIR)
    bypy -v syncup $DIR/* $DATE_YEAR/$DATE_MONTH/$(basename $DIR)
#    bypy -v syncup $DIR/* $DATE_YEAR/$DATE_MONTH/$(basename $DIR)
done
bypy list
echo -e "\033[33;1m **********百度雲盤自動同步完成********** \033[0m"
echo -e "\033[33;1m ************************************ \033[0m"

Note: 現在不能直接備份檔案夾了,只能壓縮了再上傳!!!坑B的百度網盤,要準備換個網盤了!!!

可能出現的問題

1 第一次執行要授權,開啟命令列中的提示網站,複製授權碼到命令列中

2 可能會由於百度許可權問題,使用百度雲備份需要差不多一個月跟新一次授權,否則報錯
OpenShift server failed, authorizing/refreshing with the Heroku server …

或者不小心刪除了Hash Cache File '/home/pipi/.bypy/bypy.hashcache.json' not found, no caching

Note: Skip saving Hash Cache since it has not been updated.這個應該不是錯誤,而是沒有再次更新授權的提示吧。

更新(重新)授權辦法如下:
執行bypy.py -c,刪除令牌檔案,然後重新授權一次。如果還不行,去百度應用授權裡刪除bypy再重新授權。

linux、windows檔案自動同步syncthing

syncthing安裝

linux下安裝

兩臺電腦上都要安裝

#https://github.com/syncthing/syncthing/releases
echo -e "\033[31;1m SYNC_URL=https://github.com/syncthing/syncthing/releases/download/v0.14.6/syncthing-linux-amd64-v0.14.6.tar.gz \033[0m"
SYNC_URL=https://github.com/syncthing/syncthing/releases/download/v0.14.6/syncthing-linux-amd64-v0.14.6.tar.gz
echo -e "\033[31;1m *************手動配置************* \033[0m"
echo -e "\033[31;1m *********************************** \033[0m"

echo -e "\033[31;1m *********************************** \033[0m"
echo -e "\033[31;1m *************syncthing************* \033[0m"
echo -e "\033[31;1m test -d ~/opt || mkdir -p ~/opt \033[0m"
echo -e "\033[31;1m Add the release PGP keys: \033[0m"
curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
echo -e "\033[31;1m Add the release channel to your APT sources: \033[0m"
echo "deb http://apt.syncthing.net/ syncthing release" | sudo tee /etc/apt/sources.list.d/syncthing.list
echo -e "\033[31;1m Update and install syncthing \033[0m"
sudo apt-get update
sudo apt-get install -y syncthing
echo -e "\033[31;1m syncthing & \033[0m"
syncthing &
#http://localhost:8080

最後會自動從預設瀏覽器中開啟syncthing管理介面。


安裝方式2

#https://github.com/syncthing/syncthing/releases
echo -e "\033[31;1m SYNC_URL=https://github.com/syncthing/syncthing/releases/download/v0.14.6/syncthing-linux-amd64-v0.14.6.tar.gz \033[0m"
SYNC_URL=https://github.com/syncthing/syncthing/releases/download/v0.14.6/syncthing-linux-amd64-v0.14.6.tar.gz
echo -e "\033[31;1m *************手動配置************* \033[0m"
echo -e "\033[31;1m *********************************** \033[0m"

echo -e "\033[31;1m *********************************** \033[0m"
echo -e "\033[31;1m *************syncthing************* \033[0m"
echo -e "\033[31;1m test -d ~/opt || mkdir -p ~/opt \033[0m"
test -d ~/opt || mkdir -p ~/opt
cd ~/opt
#wget $SYNC_URL
echo -e "\033[31;1m tar xzf syncthing-linux-amd64-*.tar.gz \033[0m"
tar xzf syncthing-linux-amd64-*.tar.gz
cd syncthing-linux-amd64-*/
echo -e "\033[31;1m sudo cp syncthing /usr/local/bin/ \033[0m"
sudo cp syncthing /usr/local/bin/
echo -e "\033[31;1m sed -i 's/127.0.0.1:8080/0.0.0.0:8080/g' ~/.config/syncthing/config.xml \033[0m"
sed -i 's/127.0.0.1:8080/0.0.0.0:8080/g' ~/.config/syncthing/config.xml
echo -e "\033[31;1m syncthing \033[0m"
syncthing
#http://localhost:8080

syncthing管理介面配置

管理介面地址:http://localhost:8080

設定訪問網頁管理介面的管理員使用者和密碼:點選右上角的齒輪按鈕,然後選擇Settings。(區域網上的同步不需要設定)

連線到其它伺服器:新增同步的裝置

要在各個系統之間同步檔案,你必須各自告訴它們其它伺服器的資訊。這是通過交換裝置IDs(device IDs)來實現的。

選擇“齒輪選單(gear menu)”(在右上角)中的”Show ID(顯示ID)“來找到它。

只要選擇其中一個電腦,新增另一個電腦的id就可以了,另一個電腦上就會有提示進行相互新增。

在Device區域貼上另一系統 ID **。輸入裝置名稱(可選)。在地址區域,你可以輸入其它系統的IP地址,或者使用預設值dynamic。

另一系統就會收到新增id的資訊進行雙向確認就可以了。

這個軟體只要添加了裝置id就可以自動查詢另一配對裝置的ip地址並新增(區域網和廣域網都自動新增)。

選擇要同步的資料夾

在系統上設定要同步的檔案路徑

同樣,另一個系統會收到一個確認。這時另一個系統就可以指定一個與其對應的資料夾來進行同步。

廣域網同步

上面的同步是在同一個區域網中進行的,如果想在廣域網上進行同步,可以在setting中設定監聽地址為0.0.0.0。兩臺電腦都要如此設定。

過一段比較長的時間會就可以連線上了,在廣域網上進行同步了。

連線上後自動同步的情況

 

名詞解釋

Unknown
while the GUI is loading.
Unshared
when you have not shared this folder,
Stopped
when the folder has experienced an error,
Scanning
while Syncthing is looking in the folder for local changes,
Up to Date
when the folder is in sync with the rest of the cluster,
Syncing
when this device is downloading changes from the network.

Among the folder details, you can see the current “Global State” and “Local State” summaries, as well as the amount of “Out of Sync” data if the the folder state is not up to date.

Global State
indicates how much data the fully up to date folder contains - this is basically the sum of the newest versions of all files from all connected devices. This is the size of the folder on your computer when it is fully in sync with the cluster.
Local State
shows how much data the folder actually contains right now. This can be more or less than the global state, if the folder is currently synchronizing with other devices.
Out of Sync
shows how much data needs to be synchronized from other devices. Note that this is the sum of all out of sync files - if you already have parts of such a file, or an older version of the file, less data than this will need to be transferred over the network.

ref: