您现在的位置是:备份 - 技术吧
  • CentOS安装和配置rsync

    1、配置服务端

    yum install rsync
    vi /root/rsync_user // 设置密码文件
    chmod 600 /root/rsync_user // 设置密码文件权限 
    vi /etc/rsyncd.conf // 配置服务
    vi /etc/xinetd.d/rsync // 配置服务
    chkconfig rsync on // 设置开机启动
    /usr/bin/rsync --daemon 启动服务
    ps -ef | grep rsync // 检查是否启动

    密码root_user文件内容

    test:123456
    配置文件rsyncd.conf内容
    uid = nobody
    gid = nobody
    use chroot = yes
    pid file = /var/run/rsyncd.pid
    log file = /var/run/rsyncd.log
    
    [www]
    uid = root
    gid = root
    comment = www
    path = /data/wwwroot
    auth users = test
    secrets file = /root/rsync_user
    read only = yes

    配置文件/etc/xinetd.d/rsync内容

    主要修改内容:
    disable = no
    server_args     = --config=/etc/rsyncd.conf --daemon

    # default: off
    # description: The rsync server is a good addition to an ftp server, as it \
    #       allows crc checksumming etc.
    service rsync
    {
            disable = no
            flags           = IPv6
            socket_type     = stream
            wait            = no
            user            = root
            server          = /usr/bin/rsync
            server_args     = --config=/etc/rsyncd.conf --daemon
            log_on_failure  += USERID
    }
    


    2、配置客户端

    yum install rsync
    vi /root/rsync_pass

    文件/root/rsync_pass内容

    123456


    3、在客户端测试服务

    rsync -az  test@192.168.100.2::www // 需要输入密码
    rsync -vzrtopy --progress --delete  test@192.168.100.2::www --password-file=/root/rsync_pass /www
    

    4、写shell脚本、设置定时任务

    */3 * * * * /usr/local/src/test.sh &
    test.sh文件内容


    #!/bin/bash
    cd /www
    rsync -vzrtopy --progress --delete  test@192.168.100.2::www--password-file=/root/rsync_pass /www &>/dev/null
    


    yuli0927 2018年09月11日 标签: 备份 Linux CentOS rsync分类: Linux

  • Linux服务器备份文件和数据库并上传到ftp

    #!/bin/sh
    
    backupdir="/home/data/backup/"
    if [ ! -d $backupdir ];then
            mkdir $backupdir
    fi
    
    # mkdir today backup
    today=`date +%Y-%m-%d_%H_%M_%S`
    fpath=$backupdir$today 
    echo $fpath
    if [ ! -d $fpath ];then
            mkdir $fpath
    fi
    
    # delete old file 
    find $backupdir -type f -mtime +7 -print -exec /bin/rm -f {} \;
    
    FL=`cat /usr/local/backup/file_list`
    for i in $FL ;do
            cp -Rp $i $fpath
    done
    
    #backup mail dir
    find /home/data/domains -type d >$fpath/maildirlist
    
    # backup mysql all
    /usr/local/bin/mysqldump --all-databases -uroot -pyourpasswd >$fpath/mysql_all.sql
    
    # backup my self 
    cp -Rp $0 $fpath
    cp -Rp /usr/local/backup/file_list $fpath
    
    cd $backupdir
    tar czf $today.tar.gz $today
    rm -rf $today
    cd -
    
    # ftp ...
    ftp -n<<!
    open 192.168.1.3 21
    user backup backup
    binary
    lcd $backupdir
    prompt off
    mdelete *
    mput *
    bye
    !

    yuli0927 2016年11月15日 标签: 备份 MySQL Shell Linux分类: Linux

  • MySQL数据库备份脚本

    #!/bin/sh
    cd /home/backups/sql/
    mkdir /home/backups/extmail
     
    # Remove old backups
    find /home/backups/sql/* -mtime +5 -exec rm -fr {} \; > /dev/null 2>&1
     
    # Create the filename for the backup
    eval `date "+day=%d; month=%m; year=%Y; hour=%H; min=%M; sec=%S"`
    INSTFIL="extmail-backup-$year$month$day-$hour$min$sec"
     
    # Dump the MySQL Database
    #touch /home/backups/extmail/$INSTFIL.txt
    /usr/local/bin/mysqldump -usqlback -p"sqlbackup" --opt extmail > /home/backups/extmail/$INSTFIL.sql
     
    # Gzip the whole folder
     
    tar -Pcpzf /home/backups/sql/$INSTFIL.tar.gz /home/backups/extmail/*
     
    # Remove the SQL Dump
    rm -rf /home/backups/extmail

    yuli0927 2016年04月14日 标签: 备份 MySQL Shell Linux分类: MySQL

  • 备份Mysql并上传到ftp服务器

    #!/bin/bash
    
    #MySQL设置
    MysqlHost=localhost
    MysqlUser=root
    MysqlPwd=password
    
    #备份文件设置
    BackupPath=/backup/db
    FileName=$MysqlHost-$(date +%Y%m%d-%H%M%S)
    FileFullPath=$BackupPath/$FileName
    
    #ftp设置
    FtpHost=10.206.4.121
    FtpUser=iptv
    FtpPwd=StarIptv
    FtpPath=/ftp/backup/mysql
    
    mkdir -p $BackupPath
    
    #备份mysql并导出到文件
    mysqldump -u$MysqlUser -p$MysqlPwd -h$MysqlHost --opt --all-databases -f > $FileFullPath.sql
    
    #压缩备份文件
    tar -Pzcvf $FileFullPath.tar.gz $FileFullPath.sql
    
    #上传到ftp
    ftp -n $FtpHost <<AUTOEOF
    quote USER $FtpUser
    quote PASS $FtpPwd
    cd $FtpPath
    binary
    put $FileFullPath.tar.gz $FtpPath/$FileName.tar.gz
    quit
    AUTOEOF
    
    #删除SQL文件
    rm -rf $FileFullPath.sql
    
    #删除30天之前的文件
    find $BackupPath -type f -mtime +30 -exec rm -f {} \;

    yuli0927 2016年04月14日 标签: 备份 MySQL Shell Linux分类: MySQL