#1
  1. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,161
    Rep Power
    492

    Baffled by rsync


    Hey guys
    This is probably a very basic question but I've been searching the web for a solution and not been able to find one so I'm here to ask for some help please!

    Requirement is to :-
    1. Find all files older than 30 days and write into a log/text file
    2. Rsync contents of text file from one location to another
    3. Delete the original files


    The script I have so far almost works - the problem is that when I rsync, the entire filesystem structure is created within my target folder.

    Code:
    cd /tasks/cdn/www/archive
    find /tasks/cdn/www/archive -type f -mtime +30 > /tmp/rmfilelist.txt
    rsync -avz --remove-source-files --files-from=/tmp/rmfilelist.txt / /mnt/remote_server/cdn/www/
    If I "ls" the (SOURCE) /tasks/cdn/www/archive folder, you will see:-

    Code:
    drwxr-xr-x  2 root root 4096 Apr 24  2012 2010
    drwxr-xr-x  2 root root 4096 Apr 24  2012 2011
    drwxr-xr-x 14 root root 4096 Nov 30  2012 2012
    drwxr-xr-x  8 root root 4096 May 31 23:45 2013
    If I "ls" my (TARGET) /mnt/remote_server/cdn/www I see the same folders.

    With my script above, when run, I see in my target folder that a new "tasks" folder has been created and within that, cdn/www/archive and so on.

    Here is an extract from /tmp/rmfilelist.txt ...
    Code:
    /tasks/cdn/www/archive/2013/06/12/wac_AAA1_20130612_0023.log.gz
    /tasks/cdn/www/archive/2013/06/12/www_example_198400.esclf_S.201306121300-1400-0.gz
    /tasks/cdn/www/archive/2013/06/12/wac_AAA1_20130612_0047.log.gz
    /tasks/cdn/www/archive/2013/06/12/www_example_198400.esclf_S.201306121800-1900-0.gz
    /tasks/cdn/www/archive/2013/06/12/www_example_198400.esclf_S.201306120200-0300-0.gz
    /tasks/cdn/www/archive/2013/06/12/wac_AAA1_20130611_0077.log.gz
    /tasks/cdn/www/archive/2013/06/12/wac_AAA1_20130612_0065.log.gz
    /tasks/cdn/www/archive/2013/06/12/wac_AAA1_20130612_0002.log.gz
    /tasks/cdn/www/archive/2013/06/12/wac_AAA1_20130612_0014.log.gz
    /tasks/cdn/www/archive/2013/06/12/wac_AAA1_20130612_0050.log.gz
    /tasks/cdn/www/archive/2013/06/12/wac_AAA1_20130612_0007.log.gz
    /tasks/cdn/www/archive/2013/06/12/www_example_198400.esclf_S.201306112300-2400-0.gz

    Any ideas how I would stop that from happening please?
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  2. #2
  3. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,161
    Rep Power
    492
    Got it!!!
    New working code for reference is :-

    Code:
    cd /tasks/cdn/www/archive
    find /tasks/cdn/www/archive -type f -mtime +30 > /tmp/rmfilelist.txt
    sed 's_/tasks/cdn/www/archive/_/_' /tmp/rmfilelist.txt > /tmp/rmfilelist_sedded.txt
    rsync -avz --remove-source-files --files-from=/tmp/rmfilelist_sedded.txt / /mnt/remote_server/cdn/www/
    A little bit of sed "magic" to find and replace the parent folder names and boom, away it goes!

    Comments on this post

    • aitken325i agrees
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984

IMN logo majestic logo threadwatch logo seochat tools logo