How to make a backup of (only) some system files with Mercurial - mercurial

Making a repository out of a given directory is quite straightforward. Here, I need to backup only some sparse files and directories which are spread out in the directory tree. Say, some configuration files, like /etc/ssh/sshd_config, /etc/fail2ban/jail.local, and the /var/www/, ~/.local/bin/ and ~/.config/ directories. Such, that just by cloning the repository the system gets configured after a fresh installation.
Using Mercurial, where should I init the repository, and how to add and commit the specific files and directories (using the examples above)?

It appears like you need a version control for those specific files which you just want to just install on a freshly installed system.
The best way to go with this is to track all these files in the same directory (or directory structure of your choice) and package those files in to an rpm/deb package so that when installed, it will replace the files on the freshly installation.

Related

How can I see my original source code on the server Mercurial repository?

I'm a novice in Mercurial and Phabricator.
I cannot see my source code on the server repository.
How can I see my original source code on my Mercurial repository?
I mean that if I want to compile the code on the server, which files will be used?
You can't manipulate files directly in repository as files (they doesn't exist as FS-object) - and this is true for all and any SCM.
You have to extract files from repository as unversioned tree into some location (hg help archive) or have Working Directory with files (hg help up), because usually servver-side repositories are "bare", with empty Working Directory.
Best (and standard) way to do it - use server-side hooks

Partial download by filepath with mercurial

How do you download a specific folder from a Mercurial repo? This is a similar question to partial cloning, but I don't want to actually create a local repo, since I won't be versioning these files. I just want to quickly download a specific folder containing a few KB worth of files from a repo that's several hundreds MB in size.
Specifically, I want to download all the entire "examples/plugins" folder from the Gazebo project.
I've tried searching hg's manpage and Google, but all my searches keep bringing me back to pages that assume I want to create a full repo and make a partial clone or narrow clone, which hg doesn't support.
If the Mercurial repository is running hgweb, it's possible to download a specific folder remotely. For example for the official hg repository, you can download https://www.mercurial-scm.org/repo/hg/archive/REVISION.tar.bz2/SUBPATH/.
Example: https://www.mercurial-scm.org/repo/hg/archive/19c5b0913960.tar.bz2/contrib/
This uses the 'hg archive' functionality Edward mentions, but through the web-interface.

How to prevent ignored files from being removed?

I version controlled a project settings folder a couple months back on my default branch, and then over time created many branches off default. Now I've decided that I'd rather not have the project settings folder version controlled as it creates a lot of problems when switching between branches.
So I've hg forget'd this project settings folder which lets me keep the files on my local machine but removes them mercurial. However, when switching from one of the old branches which still have this folder versioned back to the default branch it actually removes the files from the local machine, which is bad.
How do I prevent that?
The folder is also in .hgignore on default now.
It's impossible to do.
But the common practice is to keep config.ini.dist in your repository and build environment-specific config by some build-system right after you check source code out.
The standard way to deal with this is to version control a template config file and ignore the real config file. The real config file can then include the template file, or maybe the template file is copied over once in a while.
The underlying reason for your problems is that running:
$ hg forget config.ini
is exactly the same as running:
$ hg remove config.ini
$ hg cat config.ini > config.ini
The forget command leaves the file behind in your working directory, but what you commit is still a file removal. This means that afterwards, Mercurial cannot distinguish between "file was forgotten" and "file was removed" — only the removal is committed, so the two commands look exactly the same.

Mercurial to Manage Existing Website?

Getting ready to launch a website/project that was in beta testing. I want to switch it over to version control (Mercurial since I'm familiar with it).
Problem is, I am not sure how to go about doing it since the code on the website is already up and in-use and how to deal with the directories I do not need to manage (vendor and web/Upload).
Whats the best way to go about this?
Would I put the entire site into a folder, init a Merc repo, use hgignore to not track vendor and web/Upload, commit, then clone it to the live server?
Thanks! Just confused on what to do since the site is live and has user uploads.
I'm assuming you want to turn the website directory on your web server into a Mercurial repository. If that's the case, you would create a new repository somewhere on that computer, then move the .hg directory in the new repository into the website directory you want to be the root of the repository. You should then be able to run
hg add * --exclude vendor --exclude web/Upload
hg commit -m "Adding site to version control."
to get all the non-user files into version control.
I recommend, however, that you write a script or investigate tools that will deploy your website out of a repository outside your web root. You don't want your .hg directory exposed to the world. Until you get a deploy script/tool working, make sure you tell your webserver to prohibit/reject all requests to your .hg directory.

Mercurial repository backup when hidden files can not be backupped

Our company policy is not to back up hidden folders.
Is it possible to change the .hg folder name to something visible?
There's no way to rename that directory using standard mercurial configuration options. If you're on unix, and I'm guessing your are if .hg sounds hidden, you could use a pre-backup script (or cron job) to snapshot it using cp -al into something with a different name. Using -l gets you hardlinks, so it won't actually take up extra disk.
However, most people back up their .hg repositories with a push to a different mercurial server, which can be easily scripted too.
Can you create a tar archive of the repository before your company's backup cycle runs via cron?
You can always try to fool the back up system by creating a link to the .hg folder with a "backupable" name.