Categories
Storage Windows

Backup of CIFS/Samba share

By mounting a smb share on your linux machine you can make an rsnapshot of the entire share without installing cwrsync. example below

  1. Download ds_smbmount
  2. Create a script that mounts all samba shares you want to snapshot.  the script should exit with an exitcode > 0 if mounting fails.  Script is later refered to as /root/smb/radion-mount
    #!/bin/bash
    
    /root/bin/ds_smbmount -d "/mnt/share/radion/k2/foreningar" -s "//192.168.60.202/föreningar" -u backup -p mypassword -U 0 -G 1003
    if [ $? -ne "0" ]; then
     echo "Failed to mount /mnt/share/radion/k2/foreningar"
     exit 1;
    fi;
  3. Create a script that umount all samba shares after your rsnapshot is finished. script is later refered to as /root/smb/radion-umount
    #!/bin/bash
    
    umount /mnt/share/radion/k2/foreningar
  4. Configure rsnapshot to run an script before and after snapshot.
    #################################################
    # rsnapshot.conf - rsnapshot configuration file #
    #################################################
    
    #######################
    # CONFIG FILE VERSION #
    #######################
    
    config_version 1.2
    
    ###########################
    # SNAPSHOT ROOT DIRECTORY #
    ###########################
    
    # All snapshots will be stored under this root directory.
    snapshot_root /zfs-pool-2/backup/radion
    no_create_root 0
    
    #################################
    # EXTERNAL PROGRAM DEPENDENCIES #
    #################################
    
    cmd_cp /bin/cp
    cmd_rm /bin/rm
    cmd_rsync /usr/bin/rsync
    cmd_ssh /usr/bin/ssh
    cmd_logger /usr/bin/logger
    
    cmd_preexec /root/smb/radion-mount
    cmd_postexec /root/smb/radion-umount
    
    #########################################
    # BACKUP INTERVALS #
    #########################################
    
    retain daily 30
    
    ############################################
    # GLOBAL OPTIONS #
    ############################################
    
    verbose 2
    loglevel 3
    logfile /var/log/rsnapshot-radion.log
    lockfile /var/run/rsnapshot-radion.pid
    
    # Bandwith limited to 30000KB/s =~ 240Mb/s
    # default --relative removed to keep simple folder structure.
    rsync_long_args --bwlimit=30000 --delete --numeric-ids --delete-excluded
    
    
    ###############################
    ### BACKUP POINTS / SCRIPTS ###
    ###############################
    
    backup /mnt/share/radion/k2/foreningar     k2/foreningar