dsp怪胎_IT怪胎:如何保持同名文件同步

2024-01-05 11:40
文章标签 同步 保持 dsp 怪胎 同名

本文主要是介绍dsp怪胎_IT怪胎:如何保持同名文件同步,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

dsp怪胎

dsp怪胎

image

You have most likely heard of services, such as Dropbox, which are used to keep files in sync across multiple machines. However, what if you want to perform this operation on a single machine? That is, keep files which have the same file name in sync across the machine such that when one of the files changes, they are all updated.

您最可能听说过服务,例如Dropbox,这些服务用于使文件在多台计算机上保持同步。 但是,如果要在一台计算机上执行此操作怎么办? 也就是说,在机器上保持具有相同文件名的文件同步,以便当其中一个文件更改时,它们都被更新。

This functionality can be quite useful, especially for developers or system administrators where duplication of files is sometimes required.

此功能非常有用,特别是对于有时需要复制文件的开发人员或系统管理员而言。

这个怎么运作 (How it Works)

Suppose you are a web developer who, over the course of time, has put together a nice collection of Javascript functions which you use throughout all the sites you maintain. As you add or improve upon this Javascript file (let’s call it “library.js”), only the current copy you are editing is updated. This would mean, for example, if you make a bug fix or improvement you would have to manually go apply it to each of your other sites’ source code folder as well.

假设您是一个Web开发人员,随着时间的推移,他已经整理了一组不错的Javascript函数,供您在所维护的所有站点中使用。 当您添加或改进此Javascript文件时(我们将其称为“ library.js”),仅更新您正在编辑的当前副本。 例如,这意味着,如果您进行错误修复或改进,则必须手动将其应用于其他站点的每个源代码文件夹。

Our tool attempts to solve the problem of having to manually go apply the updated file to each source folder. What it does:

我们的工具试图解决必须手动将更新的文件应用于每个源文件夹的问题。 它能做什么:

  1. Searches for all files with a specified name (library.js) within a specified root folder (%UserProfile%\Documents\Web Sites).

    在指定的根文件夹(%UserProfile%\ Documents \ Web Sites)中搜索具有指定名称(library.js)的所有文件。
  2. For all files named library.js, it locates the one which was modified most recently and notes its file hash value.

    对于所有名为library.js的文件,它将找到最近修改的文件,并记录其文件哈希值。
  3. All other files named library.js (which are not the most recent updated copy) then have their file hash value compared against the most recent (determined in the previous step).

    然后,将所有其他名为library.js的文件(不是最新更新的副本)的文件哈希值与最新文件(在上一步中确定)进行比较。
  4. If the file hash values are different, then the respective copy of library.js is replaced with the most recently updated copy.

    如果文件哈希值不同,则将library.js的相应副本替换为最近更新的副本。

Because we are using hash values to compare the files, we are assured that any files replaced are indeed different than the most recent copy. For instance, if you were to run the process and 5 file replacements were made, running the process again immediately afterwards would not make any replacements since the file hash values are now identical.

因为我们使用哈希值比较文件,所以可以确保替换的文件确实与最新副本不同。 例如,如果您要运行该进程并进行了5次文件替换,则此后立即再次运行该进程将不会进行任何替换,因为文件哈希值现在相同。

更新到最新复制工具 (Update to Newest Copy Tool)

The Update to Newest Copy Tool tool is a modified version of a batch script with the same name (both are available for download using the links at the bottom of the article) which has been converted to an EXE file in order to include the required Nirsoft HashMyFiles utility. The tool must be run from the command line with certain parameters specified. If you were to just run the EXE file by double-clicking, you will get a message indicating this.

“更新到最新副本工具”工具是具有相同名称的批处理脚本的修改版本(都可以使用文章底部的链接下载),该脚本已转换为EXE文件 ,以包括所需的Nirsoft HashMyFiles实用程序 。 该工具必须使用指定的某些参数从命令行运行。 如果您只是通过双击运行EXE文件,您将收到一条消息,指示您执行此操作。

To use Update to Newest Copy, you can view the parameters by running “UpdateToNewestCopy /?” which shows the following dialog:

要使用“更新到最新副本”,可以通过运行“ UpdateToNewestCopy /?”来查看参数。 显示以下对话框:

image

The only required parameters are the SourceFolder (e.g. %UserProfile%\Documents\Web Sites) and the FileName (library.js). However, you can alter the functionality by adding additional switches as described above.

唯一必需的参数是SourceFolder(例如%UserProfile%\ Documents \ Web Sites)和FileName(library.js)。 但是,您可以通过添加如上所述的其他开关来更改功能。

Examples

例子

The following command would find all files named “Common.vb” within the folder “C:\users\jfaulkner\documents\Code Files”, performing the replacement but making a backup of the current copy before overwriting (this output is what produced the top image for this article):

以下命令将在文件夹“ C:\ users \ jfaulkner \ documents \ Code Files”中找到所有名为“ Common.vb”的文件,执行替换操作,但在覆盖之前对当前副本进行备份(此输出是产生本文的顶部图片):

UpdateToNewestCopy “C:\users\jfaulkner\documents\Code Files” Common.vb /B

UpdateToNewestCopy“ C:\ users \ jfaulkner \ documents \ Code文件” Common.vb / B

The following command performs the same search action as above, however it only reports on files which would be replaced and does not actually perform any file operations:

以下命令执行与上述相同的搜索操作,但是它仅报告将被替换的文件,而实际上不执行任何文件操作:

UpdateToNewestCopy “C:\users\jfaulkner\documents\Code Files” Common.vb /V

UpdateToNewestCopy“ C:\ users \ jfaulkner \ documents \ Code文件” Common.vb / V

Assume there is a file named “C:\Config\FilesToSearch.txt” with the following contents:

假设有一个名为“ C:\ Config \ FilesToSearch.txt”的文件,其内容如下:

library.js Common.vb

library.js Common.vb

The following command would search the my documents folder of the current user and report on any updates to “library.js” and “Common.vb”, but would not actually perform any update operations:

以下命令将搜索当前用户的“我的文档”文件夹,并报告对“ library.js”和“ Common.vb”的任何更新,但实际上不会执行任何更新操作:

UpdateToNewestCopy “%UserProfile%\Documents” “C:\Config\FilesToSearch.txt” /L /V

UpdateToNewestCopy“%UserProfile%\ Documents”“ C:\ Config \ FilesToSearch.txt” / L / V

流程自动化 (Automating the Process)

This process is an ideal candidate for automation. By creating a scheduled task (nothing special required) with the specified settings and having it run daily/hourly/every 15 minutes (depending on your requirements), you can keep files sync’ed in true set-it-and-forget-it fashion.

此过程是自动化的理想选择。 通过使用指定的设置创建计划任务 (不需要任何特殊操作)并使其每天/每小时/每15分钟运行一次(取决于您的要求),您可以使文件保持真正的“设置后忘记”状态时尚。

下载 (Download)

Update to Newest Copy – modified executable format

更新为最新副本–修改后的可执行格式

Update to Newest Copy – source batch files (more command line oriented)

更新到最新副本–源批处理文件 (更多面向命令行)

翻译自: https://www.howtogeek.com/163824/it-geek-how-to-keep-files-with-the-same-name-in-sync/

dsp怪胎

这篇关于dsp怪胎_IT怪胎:如何保持同名文件同步的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/572744

相关文章

Python 中的异步与同步深度解析(实践记录)

《Python中的异步与同步深度解析(实践记录)》在Python编程世界里,异步和同步的概念是理解程序执行流程和性能优化的关键,这篇文章将带你深入了解它们的差异,以及阻塞和非阻塞的特性,同时通过实际... 目录python中的异步与同步:深度解析与实践异步与同步的定义异步同步阻塞与非阻塞的概念阻塞非阻塞同步

Linux搭建Mysql主从同步的教程

《Linux搭建Mysql主从同步的教程》:本文主要介绍Linux搭建Mysql主从同步的教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux搭建mysql主从同步1.启动mysql服务2.修改Mysql主库配置文件/etc/my.cnf3.重启主库my

Java中将异步调用转为同步的五种实现方法

《Java中将异步调用转为同步的五种实现方法》本文介绍了将异步调用转为同步阻塞模式的五种方法:wait/notify、ReentrantLock+Condition、Future、CountDownL... 目录异步与同步的核心区别方法一:使用wait/notify + synchronized代码示例关键

详谈redis跟数据库的数据同步问题

《详谈redis跟数据库的数据同步问题》文章讨论了在Redis和数据库数据一致性问题上的解决方案,主要比较了先更新Redis缓存再更新数据库和先更新数据库再更新Redis缓存两种方案,文章指出,删除R... 目录一、Redis 数据库数据一致性的解决方案1.1、更新Redis缓存、删除Redis缓存的区别二

Nacos集群数据同步方式

《Nacos集群数据同步方式》文章主要介绍了Nacos集群中服务注册信息的同步机制,涉及到负责节点和非负责节点之间的数据同步过程,以及DistroProtocol协议在同步中的应用... 目录引言负责节点(发起同步)DistroProtocolDistroSyncChangeTask获取同步数据getDis

基于MySQL Binlog的Elasticsearch数据同步实践

一、为什么要做 随着马蜂窝的逐渐发展,我们的业务数据越来越多,单纯使用 MySQL 已经不能满足我们的数据查询需求,例如对于商品、订单等数据的多维度检索。 使用 Elasticsearch 存储业务数据可以很好的解决我们业务中的搜索需求。而数据进行异构存储后,随之而来的就是数据同步的问题。 二、现有方法及问题 对于数据同步,我们目前的解决方案是建立数据中间表。把需要检索的业务数据,统一放到一张M

服务器集群同步时间手记

1.时间服务器配置(必须root用户) (1)检查ntp是否安装 [root@node1 桌面]# rpm -qa|grep ntpntp-4.2.6p5-10.el6.centos.x86_64fontpackages-filesystem-1.41-1.1.el6.noarchntpdate-4.2.6p5-10.el6.centos.x86_64 (2)修改ntp配置文件 [r

高并发环境中保持幂等性

在高并发环境中保持幂等性是一项重要的挑战。幂等性指的是无论操作执行多少次,其效果都是相同的。确保操作的幂等性可以避免重复执行带来的副作用。以下是一些保持幂等性的常用方法: 唯一标识符: 请求唯一标识:在每次请求中引入唯一标识符(如 UUID 或者生成的唯一 ID),在处理请求时,系统可以检查这个标识符是否已经处理过,如果是,则忽略重复请求。幂等键(Idempotency Key):客户端在每次

MySQL主从同步延迟原理及解决方案

概述 MySQL的主从同步是一个很成熟的架构,优点为: ①在从服务器可以执行查询工作(即我们常说的读功能),降低主服务器压力; ②在从主服务器进行备份,避免备份期间影响主服务器服务; ③当主服务器出现问题时,可以切换到从服务器。 相信大家对于这些好处已经非常了解了,在项目的部署中也采用这种方案。但是MySQL的主从同步一直有从库延迟的问题,那么为什么会有这种问题。这种问题如何解决呢? MyS

使用条件变量实现线程同步:C++实战指南

使用条件变量实现线程同步:C++实战指南 在多线程编程中,线程同步是确保程序正确性和稳定性的关键。条件变量(condition variable)是一种强大的同步原语,用于在线程之间进行协调,避免数据竞争和死锁。本文将详细介绍如何在C++中使用条件变量实现线程同步,并提供完整的代码示例和详细的解释。 什么是条件变量? 条件变量是一种同步机制,允许线程在某个条件满足之前进入等待状态,并在条件满