Results 1 to 3 of 3

Thread: rsync remove old backup on remote PC

  1. #1
    Join Date
    Feb 2013
    Beans
    2

    rsync remove old backup on remote PC

    Good day

    I use this script to backup my home PC to remote PC

    Code:
    #!/bin/bash
    #Todays date in ISO-8601 format:
    DAY0=`date -I`
    
    #Yesterdays date in ISO-8601 format:
    DAY1=`date -I -d "1 day ago"`
    
    #The source directory:
    SRC="/home/honza/Downloads/"
    
    #The target directory:
    TRG="honza@192.168.80.197:/media/zaloha/$DAY0"
    
    #The link destination directory:
    LNK="/media/zaloha/$DAY1"
    
    #The rsync options:
    OPT="-avh --delete --link-dest=/honza@192.168.80.195:/media/zaloha/$DAY1"
    
    #Execute the backup
    rsync $OPT $SRC $TRG
    
    #29 days ago in ISO-8601 format
    DAY3=`date -I -d "3 days ago"`
    
    #Delete the backup from 29 days ago, if it exists
    if [ -d /honza@192.168.80.197:/media/zaloha/$DAY3 ]
    then
    rm -R /honza@192.168.80.197:/media/zaloha/$DAY3
    fi
    I dont't know how to delete old backup than 3 days. Script works well when I backup on the same PC but not on a remote.

    Code:
    --link-dest arg does not exist: /honza@192.168.80.195:/media/zaloha/2013-03-15
    and old backups are not deleted.

    thank you

  2. #2
    Join Date
    Oct 2008
    Location
    Ottawa, Canada
    Beans
    813
    Distro
    Kubuntu 20.04 Focal Fossa

    Re: rsync remove old backup on remote PC

    You should remove the leading / from /honza@192.168.80.195:/media/zaloha/...
    The way it is, the leading slash makes your destination appear local.
    Also, when testing the existence of old backup directories, you will have to use tools like sftp, if the remote dir is accessed by SSH.

    Personally, I would use sshfs to mount the remote machine locally, then perform rsync and rm operations on the mounted location.
    Code:
    sshfs honza@192.168.80.195:/media/zaloha /local-dir-for-rsync # mount the remote dir locally
    <script operations>
    fusermount -u /local-dir-for-rsync # unmount the remote dir
    Cheers!
    Last edited by LewisTM; February 21st, 2013 at 03:18 PM.
    husband@wife$ make sandwich
    Permission denied
    husband@wife$ sudo make sandwich

  3. #3
    Join Date
    Jun 2006
    Location
    Brisbane Australia
    Beans
    713

    Re: rsync remove old backup on remote PC

    rsnapshot is a standard debian/ubuntu package that does all that for you.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •