User Tag List

Resultados 1 al 6 de 6

Tema: Sincronizar directorios con rsync

  1. #1

    Fecha de ingreso
    Sep 2006
    Ubicación
    Malaga
    Mensajes
    7,573
    Mencionado
    47 Post(s)
    Tagged
    0 Tema(s)
    Agradecer Thanks Given 
    1,676
    Agradecer Thanks Received 
    1,930
    Thanked in
    Agradecido 1,293 veces en [ARG:2 UNDEFINED] posts

    Question Sincronizar directorios con rsync

    A ver, tengo un script que hace esto para hacer la copia de seguridad de las cosas que hago, DST esta en otro disco duro. Solo copia los ficheros nuevos o modificados y los que he borrado los quita del directorio de backup.

    rsync -rvcpo --prune-empty-dirs --delete SRC DST

    He hecho otro script para sincronizar el contenido de la tarjeta de la MiST con un directorio donde tengo todos los cores y roms, pues resulta que como la tarjeta tiene que estar formateada en FAT32 no me borra lo que voy quitando porque no me interesa. He buscado pero no doy con la tecla, ademas de que tarda un egg en sincronizar los directorios (es por la opción -c que hace un CRC de los fichero).

    ¿Sabeis de alguna solución u otro comando para sincronizar entre APFS y FAT32?
    Última edición por swapd0; 09/04/2022 a las 14:53
    No es lo mismo tener diez años de experiencia, que tener un año de experiencia diez veces.


    It is an undisputed truth that the Atari ST gets the best out of coders. No dedicated hardware, just the CPU and a frame buffer! Some call it Spartan, others name it Power Without The Price, and a select few say `challenge accepted'! --- by spkr from smfx

  2. #2

    Fecha de ingreso
    Nov 2005
    Ubicación
    Excartagenero
    Mensajes
    23,719
    Mencionado
    276 Post(s)
    Tagged
    0 Tema(s)
    Agradecer Thanks Given 
    6,012
    Agradecer Thanks Received 
    5,866
    Thanked in
    Agradecido 3,823 veces en [ARG:2 UNDEFINED] posts
    Entradas de blog
    1
    Seguramente lo que te voy a decir no sirve de nada :P

    Yo hago mis copias de seguridad usando DSyncronize:
    https://portableapps.com/apps/utilit...onize_portable

    Tiene para meter un monton de filtros y de opciones, ademas se pueden crear distintas configuraciones etc.

    Ahí lo dejo por si es de futilidad.

  3. #3

    Fecha de ingreso
    Sep 2006
    Ubicación
    Malaga
    Mensajes
    7,573
    Mencionado
    47 Post(s)
    Tagged
    0 Tema(s)
    Agradecer Thanks Given 
    1,676
    Agradecer Thanks Received 
    1,930
    Thanked in
    Agradecido 1,293 veces en [ARG:2 UNDEFINED] posts
    No hay version para Mac , voy a ver si encuentro algo parecido, aunque preferiría el script lo ejecutas y te olvidas.

    -----Actualizado-----

    Que porras, a ver si me entran ganas y hago un programa que lo haga :P
    No es lo mismo tener diez años de experiencia, que tener un año de experiencia diez veces.


    It is an undisputed truth that the Atari ST gets the best out of coders. No dedicated hardware, just the CPU and a frame buffer! Some call it Spartan, others name it Power Without The Price, and a select few say `challenge accepted'! --- by spkr from smfx

  4. #4

    Fecha de ingreso
    Nov 2005
    Ubicación
    Excartagenero
    Mensajes
    23,719
    Mencionado
    276 Post(s)
    Tagged
    0 Tema(s)
    Agradecer Thanks Given 
    6,012
    Agradecer Thanks Received 
    5,866
    Thanked in
    Agradecido 3,823 veces en [ARG:2 UNDEFINED] posts
    Entradas de blog
    1
    Cita Iniciado por swapd0 Ver mensaje
    Que porras, a ver si me entran ganas y hago un programa que lo haga :P
    Si tienes las herramientas, conocimientos y tiempo, muchas veces es la mejor solución.

    -----Actualizado-----

    Hasta hace unos meses yo llevaba la contabilidad de la casa, trabajos y cosas en una planilla de calculo, pero definitivamente cada vez se me hacía mas complicado.
    Me puse a buscar opciones, algun proyecto instalable en un servidor web (no un servicio online de terceros) y hay tantos... con tantas opciones... que ya solo buscar y probar lo vi como un problema, luego configurarlo y que haga lo que yo quiero y como lo quiero.

    Total, me puse y con mi php-frameworcito y Bootstrap me monté lo que quería y como lo quería. :P

  5. El siguiente usuario agradece a josepzin este mensaje:

    swapd0 (09/04/2022)

  6. #5

    Fecha de ingreso
    Sep 2006
    Ubicación
    Malaga
    Mensajes
    7,573
    Mencionado
    47 Post(s)
    Tagged
    0 Tema(s)
    Agradecer Thanks Given 
    1,676
    Agradecer Thanks Received 
    1,930
    Thanked in
    Agradecido 1,293 veces en [ARG:2 UNDEFINED] posts
    Aqui una primera version, creo que va, he tardado mas de lo que me pensaba por problemas de privilegios con los directorios que crea el OSX (maldito .Spotlight-V100).

    Depende de las Boost pero creo que las librerias boost::filesystem ya son parte del standar de C++11 o tal vez C++14, me daba pereza probar.

    Esto para la gente que dice que hacer cosas en C++ es difícil y por eso programan en Python :P
    Código:
    #include <iostream>
    #include <set>
    #include <string>
    
    
    #include <boost/filesystem.hpp>
    
    
    std::set<boost::filesystem::path> get_files(constboost::filesystem::path &path)
    {
        std::set<boost::filesystem::path> files;
        boost::filesystem::recursive_directory_iterator it(path);//, boost::filesystem::skip_permission_denied);
        boost::filesystem::recursive_directory_iterator end;
    
    
        while ( it != end )
        {
            files.insert(boost::filesystem::relative(it->path(), path));
           try
            {
                ++it;
            } catch (boost::filesystem::filesystem_error e)
            {
               // para que no pete el .Spotlight-V100
                it.disable_recursion_pending();
                ++it;
            }
        }
    
    
        std::cout << files.size() << " files at " << path.string() << std::endl;
    
    
        return files;
    }
    
    
    // return a - b
    std::set<boost::filesystem::path> sub(conststd::set<boost::filesystem::path> &a, std::set<boost::filesystem::path> &b)
    {
       std::set<boost::filesystem::path> tmp;
        for ( auto &path : a )
            if ( b.find(path) == b.end() )
                tmp.insert(path);
    
    
        return tmp;
    }
    
    
    int main(int argc, const char * argv[])
    {
        if ( argc < 3 )
        {
            std::cout << "dsync SRC DST\nby swap d0 9/4/2022\n";
            return 1;
        }
    
    
       boost::system::error_code error;
        auto srcPath = boost::filesystem::canonical(argv[1], boost::filesystem::current_path().string(), error);
        auto dstPath = boost::filesystem::canonical(argv[2], boost::filesystem::current_path().string(), error);
    
    
        if ( !boost::filesystem::exists(srcPath) )
        {
            std::cout << "Source directory not found: " << srcPath.string() << std::endl;;
           return 1;
        }
    
    
        if ( !boost::filesystem::exists(dstPath) )
        {
           std::cout << "Destination directory not found: " << dstPath.string() << std::endl;;
           return 1;
        }
    
    
        auto srcFiles = get_files(argv[1]);
        auto dstFiles = get_files(argv[2]);
    
    
        auto copyFiles = sub(srcFiles, dstFiles);
        auto deleteFiles = sub(dstFiles, srcFiles);
    
    
    // delete files
        for ( auto &file : deleteFiles )
        {
            std::cout << "Deleting " << (dstPath / file).string() << std::endl;
           try
            {
                boost::filesystem::remove(dstPath / file);
            }
            catch (...)
            {
               // para el maldito .Spotlight-V100
                std::cout << "Can't delete " << (dstPath / file).string() << std::endl;
            }
        }
    
       // copy files
        for ( auto &file : copyFiles )
        {
            std::cout << "Copying " << (srcPath / file).string() << std::endl;
            boost::filesystem::copy(dstPath /file, dstPath / file);
        }
    
    
       return 0;
    }
    Última edición por swapd0; 09/04/2022 a las 20:35
    No es lo mismo tener diez años de experiencia, que tener un año de experiencia diez veces.


    It is an undisputed truth that the Atari ST gets the best out of coders. No dedicated hardware, just the CPU and a frame buffer! Some call it Spartan, others name it Power Without The Price, and a select few say `challenge accepted'! --- by spkr from smfx

  7. Los siguientes 2 usuarios agradecen a swapd0 este post:

    Karkayu (10/04/2022), selecter25 (10/04/2022)

  8. #6

    Fecha de ingreso
    Sep 2006
    Ubicación
    Malaga
    Mensajes
    7,573
    Mencionado
    47 Post(s)
    Tagged
    0 Tema(s)
    Agradecer Thanks Given 
    1,676
    Agradecer Thanks Received 
    1,930
    Thanked in
    Agradecido 1,293 veces en [ARG:2 UNDEFINED] posts
    Uppss, se me olvido actualizar los ficheros que están en los dos sitios pero con distinta fecha.


    Edited: porras, como se jode la indentacion del código XD
    Código:
    #include <iostream>
    #include <set>
    #include <string>
    
    
    #include <boost/filesystem.hpp>
    
    
    std::set<boost::filesystem::path> get_files(constboost::filesystem::path &path)
    {
    std::set<boost::filesystem::path> files;
    boost::filesystem::recursive_directory_iterator it(path);//, boost::filesystem::skip_permission_denied);
    boost::filesystem::recursive_directory_iterator end;
    
    
        while ( it != end )
        {
            files.insert(boost::filesystem::relative(it->path(), path));
    try
            {
                ++it;
            } catch (boost::filesystem::filesystem_error e)
            {
    // para que no pete el .Spotlight-V100
                it.disable_recursion_pending();
                ++it;
            }
        }
    
    
        std::cout << files.size() << " files at " << path.string() << std::endl;
    
    
        return files;
    }
    
    
    bool never(constboost::filesystem::path &a, constboost::filesystem::path &b)
    {
    returnfalse;
    }
    
    
    bool always(constboost::filesystem::path &a, constboost::filesystem::path &b)
    {
    returntrue;
    }
    
    
    // return date(a) > date(b)
    bool newer(constboost::filesystem::path &a, constboost::filesystem::path &b)
    {
    if ( boost::filesystem::is_regular_file(a) && boost::filesystem::is_regular_file(b) )
    returnboost::filesystem::last_write_time(a) > boost::filesystem::last_write_time(b);
    else
    returnfalse;
    }
    
    
    // return a - b
    std::set<boost::filesystem::path> sub(conststd::set<boost::filesystem::path> &a, std::set<boost::filesystem::path> &b)
    {
    std::set<boost::filesystem::path> tmp;
        for ( auto &path : a )
        {
            if ( b.find(path) == b.end() )
                tmp.insert(path);
        }
    
    
        return tmp;
    }
    
    
    std::set<boost::filesystem::path> cmp(constboost::filesystem::path &abase, conststd::set<boost::filesystem::path> &a
                                          , const boost::filesystem::path &bbase, std::set<boost::filesystem::path> &b
                                          , bool(*fn)(const boost::filesystem::path &a, const boost::filesystem::path &b) = never)
    {
    std::set<boost::filesystem::path> tmp;
        for ( auto &path : a )
        {
            auto it = b.find(path);
            if ( it == b.end() || fn(abase / path, bbase / *it) )
                tmp.insert(path);
        }
    
        return tmp;
    }
    
    
    int main(int argc, const char * argv[])
    {
        if ( argc < 3 )
        {
    std::cout << "dsync SRC DST\nby swap d0 9/4/2022\n";
    return1;
        }
    
    
    boost::system::error_code error;
        auto srcPath = boost::filesystem::canonical(argv[1], boost::filesystem::current_path().string(), error);
        auto dstPath = boost::filesystem::canonical(argv[2], boost::filesystem::current_path().string(), error);
    
    
        if ( !boost::filesystem::exists(srcPath) )
        {
            std::cout << "Source directory not found: " << srcPath.string() << std::endl;;
    return1;
        }
    
    
        if ( !boost::filesystem::exists(dstPath) )
        {
    std::cout << "Destination directory not found: " << dstPath.string() << std::endl;;
    return1;
        }
    
    
        auto srcFiles = get_files(srcPath);
        auto dstFiles = get_files(dstPath);
    
    
        auto copyFiles = sub(srcFiles, dstFiles);
        auto updateFiles = cmp(srcPath, srcFiles, dstPath, dstFiles, newer);
        auto deleteFiles = sub(dstFiles, srcFiles);
    
    
    // delete files
        for ( auto &file : deleteFiles )
        {
            std::cout << "Deleting " << (dstPath / file).string() << std::endl;
    try
            {
                boost::filesystem::remove(dstPath / file);
            }
            catch (...)
            {
    // para el maldito .Spotlight-V100
                std::cout << "Can't delete " << (dstPath / file).string() << std::endl;
            }
        }
    
    // copy files
        for ( auto &file : copyFiles )
        {
            std::cout << "Copying " << (srcPath / file).string() << std::endl;
            boost::filesystem::copy(dstPath /file, dstPath / file);
        }
    
    
    // update files
        for ( auto &file : updateFiles )
        {
            std::cout << "Updating " << (srcPath / file).string() << std::endl;
            boost::filesystem::copy_file(srcPath /file, dstPath / file, boost::filesystem::copy_option::overwrite_if_exists);
        }
    
    
    return0;
    }
    Última edición por swapd0; 11/04/2022 a las 01:20
    No es lo mismo tener diez años de experiencia, que tener un año de experiencia diez veces.


    It is an undisputed truth that the Atari ST gets the best out of coders. No dedicated hardware, just the CPU and a frame buffer! Some call it Spartan, others name it Power Without The Price, and a select few say `challenge accepted'! --- by spkr from smfx

  9. El siguiente usuario agradece a swapd0 este mensaje:

    Karkayu (10/04/2022)

Etiquetas para este tema

Permisos de publicación

  • No puedes crear nuevos temas
  • No puedes responder temas
  • No puedes subir archivos adjuntos
  • No puedes editar tus mensajes
  •