Archive for 一月, 2018


rsync小记

一、通过SSH备份到远程主机
#!/bin/bash
rsync -aqzH –delete -e ‘ssh -p 2222’ /folder/to/backup remoteuser@remotehost:/location/of/backup &> /dev/null

二、每日创建全量或增量备份
#!/bin/bash
DAY=$(date +%A)

if [ -e /location/to/backup/incr/$DAY ] ; then
rm -fr /location/to/backup/incr/$DAY
fi

rsync -a –delete –inplace –backup –backup-dir=/location/to/backup/incr/$DAY /folder/to/backup/ /location/to/backup/full/ &> /dev/null

三、快照备份
#!/bin/bash
# Basic snapshot-style rsync backup script
# Config
OPT="-aPh"
LINK="–link-dest=/snapshots/username/last/"
SRC="/home/username/files/"
SNAP="/snapshots/username/"
LAST="/snapshots/username/last"
date=`date “+%Y-%b-%d:_%T"`

# Run rsync to create snapshot
rsync $OPT $LINK $SRC ${SNAP}$date

# Remove symlink to previous snapshot
rm -f $LAST

# Create new symlink to latest snapshot for the next backup to hardlink
ln -s ${SNAP}$date $LAST

四、复杂版快照备份
#!/bin/bash
## my own rsync-based snapshot-style backup procedure
# config vars
SRC="/home/username/files/" #dont forget trailing slash!
SNAP="/snapshots/username"
OPTS="-rltgoi –delay-updates –delete –chmod=a-w"
MINCHANGES=20

# run this process with real low priority
ionice -c 3 -p $$
renice +12 -p $$

# sync
rsync $OPTS $SRC $SNAP/latest >> $SNAP/rsync.log

# check if enough has changed and if so
# make a hardlinked copy named as the date

COUNT=$( wc -l $SNAP/rsync.log|cut -d" " -f1 )
if [ $COUNT -gt $MINCHANGES ] ; then
DATETAG=$(date +%Y-%m-%d)
if [ ! -e $SNAP/$DATETAG ] ; then
cp -al $SNAP/latest $SNAP/$DATETAG
chmod u+w $SNAP/$DATETAG
mv $SNAP/rsync.log $SNAP/$DATETAG
chmod u-w $SNAP/$DATETAG
fi
fi

五、备份LINUX整个系统
rsync -aAXv –exclude={“/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /path/to/backup/folder

六、还原备份的LINUX系统
rsync -qaHAXS SOURCE_DIR DESTINATION_DIR

还原后,还要更改fstab和重新安装grub
1、编辑/DESTINATION_DIR/etc/fstab注意事项,用LABLE的自己直接就改了。
查看UUID:
blkid /dev/sdaX
ls -l /dev/disk/by-uuid/

2、重装grub
先挂载,然后chroot
mount –bind /proc /DESTINATION_DIR/proc
mount –bind /sys /DESTINATION_DIR/sys
mount –bind /dev /DESTINATION_DIR/dev
mount –bind /run /DESTINATION_DIR/run
chroot /DESTINATION_DIR
重装GRUB并更新GRUB的配置
grub-install /dev/sda
update-grub

豆瓣:http://pypi.douban.com/simple/
阿里云:http://mirrors.aliyun.com/pypi/simple/

临时使用:
可以在使用pip的时候加参数-i https://mirrors.aliyun.com/pypi/simple
例如:pip install -i https://mirrors.aliyun.com/pypi/simple pyspider

彻底替换下载源:
修改 ~/.pip/pip.conf(没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)
[global]
index-url = https://mirrors.aliyun.com/pypi/simple
[install]
trusted-host=mirrors.aliyun.com