文件自动备份和同步bypy和syncthing

http://blog.csdn.net/pipisorry/article/details/52464402

Linux定时备份数据到百度云盘

sudo pip3 install requests
sudo pip3 install bypy

备份脚本示例

#!/bin/sh
# File:    ~/bysync.sh
# Author:  pipi
# Email: pipisorry@126.com

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再重新授权。

[houtianze/bypy]

[Linux定时备份数据到百度云盘]

皮皮blog



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管理界面。

[Community Contributions]


安装方式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

皮皮blog

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.

[An intro to the GUI]

[Syncthing: 一个在计算机之间同步文件/文件夹的私密安全同步工具]

[Syncthing’s documentation]*

from: http://blog.csdn.net/pipisorry/article/details/52464402

ref:


### 使用 `bypy` 上传大文件 当使用 `bypy` 工具上传大文件时,由于网络条件或其他因素的影响,可能会遇到一些特殊问题。以下是关于如何通过 `bypy` 实现大文件分片上传以及解决可能存在的 MD5 值不匹配问题的相关说明。 #### 大文件分片上传方法 对于较大的文件,`bypy` 自动支持分片上传功能。这意味着无需手动干预即可完成大文件的分割与合并操作。然而,在某些情况下,可能出现因百度服务器返回错误的 MD5 值而导致同步失败的情况[^2]。为了避免此类问题的发生,可以采取以下措施: 1. **启用详细日志模式** 在执行上传命令时加入 `-v` 参数以开启详细的调试信息输出。这样可以帮助定位潜在的问题并确认每一片段是否成功传输至云端。 ```bash bypy -v upload large_file_path remote_directory_path ``` 2. **验证文件一致性** 如果发现本地与远程文件存在差异,则需重新校验其内容完整性。尽管此过程较为耗时,但它能够有效防止数据丢失或损坏的风险。 3. **调整配置参数** 用户还可以尝试修改默认设置来优化性能表现。例如增大单次请求的数据量或者缩短超时时间间隔等选项均有助于提高效率。 #### 需要注意事项 - 确保已安装必要的依赖库如Python Requests模块[^4],否则可能导致程序运行异常终止。 - 利用磁盘空间统计工具检查当前目录结构以便合理规划存储布局[^3]。 ```python import os from tqdm import tqdm def monitor_upload(file_size, chunk_size=1024*1024): progress_bar = tqdm(total=file_size, unit='B', unit_scale=True) def callback(sent_bytes): progress_bar.update(chunk_size) return callback # Example usage with bypy API (pseudo-code illustration only) upload_result = bypy.upload('local_large_file', 'remote/path/', callback=monitor_upload(os.path.getsize('local_large_file'))) progress_bar.close() print(f"Upload completed: {upload_result}") ``` 上述脚本片段展示了如何结合第三方进度条库`tqdm`实现自定义回调函数从而实时跟踪上传状态变化情况。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值