Archive

Archives pour 03/2021

Merging directories (folders) on Mac OS X

29/03/2021 Comments off

merging directoriesEvery now and then I find myself in a situation where I have a folder (I’ll call it source) of files and nested folders, possibly many levels deep, that I want to copy into another folder (which I’ll call target). target already contains some of the files and folders I’m copying, and it also has files and folders that are not present in source.

Simply copying source to target’s parent folder in the Mac OS X Finder will replace everything in target with the contents of source. This is not always what I want, and in my opinion it’s one of the biggest flaws of the Mac OS X Finder. Not just Mac OS X actually – back in the pre-Mac OS X days there was a utility called Speed Doubler that patched the Finder to add a smart replace option when copying files.

It’s possible to manually open each folder and their subfolders and copy just the files, but it can be very tedious. There are also third party software options that let you merge files when copying, and if you have Apple’s Developer Tools installed there is the FileMerge utility.

However, you can open a Terminal window and copy the files from the command line, which saves you from installing extra software. Since I keep looking up the syntax every time I need to do this I decided to document it here for future reference.

cp

One command line utility that can copy directories without replacing everything in them is cp:

cp -pRv source/ target

The pRv options do the following:

  • p preserves timestamps, flags, modes, and ownerships of files
  • R copies the entire subtree
  • v makes cp output the name of each file that is copied

Note: The / after the name of the source directory is important since it tells cp to copy the contents of the directory and not the directory itself.

rsync

You can also use rsync:

rsync -av source/ target

The av options do this:

  • a tells rsync to copy recursively and preserve file attributes
  • v makes rsync print information to the terminal window about what was copied

Just as with the cp command, the trailing slash after the source directory is important to make sure only the contents of the directory are copied.

ditto

A third option is ditto:

ditto -V source target

The V option prints information about what was copied.

Deleting files that don’t exist in the source directory

Sometimes you want a merge to delete files that exist in the target directory but not in the source directory. That’s easy with rsync (but be careful as there is no undo):

rsync -av --delete source/ target

But wait! What if the target is under version control? Won’t that delete any .svn or .git directories as well? Yep. That can be avoided by adding filters. Let’s say you want to keep all .htaccess and .svn files or directories in the target directory. This does just that:

rsync -av --delete --filter="- .htaccess" --filter="- .svn" source/ target

A useful tip when you involve delete is to add the n option at first to do a “dry run” and only show what would have been deleted. Again, be careful with delete since there is no undo.

Hoping for Finder integration

It would be great if Apple could make it possible to use the Finder to copy folders like this. It could be a secret option somewhere or invoked when you hold certain modifier keys when copying. It doesn’t matter as long as it’s possible.

Most people probably don’t need this feature every day, but when you do need it it can save lots of time. Having the feature built into the Finder would also reduce the risk of people accidentally deleting files because they don’t realise copying folders replaces everything inside them.

 
Categories: Logiciel, Système Tags: , , ,

Supervision de postfix via mailgraph avec le plugin check_mailstat.pl via Nagios/Centreon

28/03/2021 Comments off

Source:  l’admin sous GNU/Linux – blog libreCentreon_graph_mailstat_home

 

Voici une procédure permettant de contrôler l’activité d’un serveur de messagerie postfix via Nagios / Centreon.

Pour cela nous allons utiliser le plugins check_mailstat.pl avec une petite adaptation du script afin de le rendre compatible avec la génération de graphe sous Centreon.

Le plugin check_mailstat.pl va récupérer depuis des données depuis mailgraph qui permet de générer des graphes via RRDTool

Tout d’abord, il faut installer Mailgraph sur l’hôte à superviser, ici une Debian.

Installation de Mailgraph

aptitude install mailgraph

Si l’installation ne vous a pas poser les questions propres au paramétrage, lancer :

dpkg-reconfigure mailgraph

Voici les questions et réponse à fournir :

Mailgraph doit-il être lancé au démarrage ? OUI

Fichier de journalisation à utiliser par mailgraph : /var/log/mail.log (à adapter)

Faut-il compter les courriels entrants comme des courriels sortants ? NON (J’utilise Amavis, donc j’ai choisi cette option, encore une fois à adapter.

Lire la suite…

MySQL – Optimisation

28/03/2021 Comments off

L’optimisation au niveau de MySQL passe par trois composants, à savoir :

  • Optimisation du serveur MySQL
  • Optimisation de la base de données
  • Optimisation des requêtes Lire la suite…

Monitorer fail2ban

27/03/2021 Comments off

Source: arscenic.org

Nous avons installé fail2ban sur chacun de nos serveurs en utilisant ce tutoriel

Le script de monitoring que nous allons utiliser se trouve ici : http://blog.sinnwidrig.org/?p=50. C’est un script générique permettant de créer un graphique distinct par action de fail2ban.

On décide de placer les plugins supplémentaires pour munin dans le répertoire  /opt/share/munin/plugins
#Créer le répertoire des plugins dans le cas ou il n'existe pas déjà
sudo mkdir -p /opt/share/munin/plugins
cd /opt/share/munin/plugins
# Récupérer le script
sudo wget http://blog.sinnwidrig.org/files/fail2ban_-0.1
# Rendre exécutable le script
sudo chmod +x fail2ban_-0.1

Lire la suite…

Howto: Performance Benchmarks a Webserver

27/03/2021 Comments off

source: nixCraft

You can benchmark Apache, IIS and other web server with apache benchmarking tool called ab. Recently I was asked to performance benchmarks for different web servers.

Apache benchmark

Apache benchmark

It is true that benchmarking a web server is not an easy task. From how to benchmark a web server:

First, benchmarking a web server is not an easy thing. To benchmark a web server the time it will take to give a page is not important: you don’t care if a user can have his page in 0.1 ms or in 0.05 ms as nobody can have such delays on the Internet.

What is important is the average time it will take when you have a maximum number of users on your site simultaneously. Another important thing is how much more time it will take when there are 2 times more users: a server that take 2 times more for 2 times more users is better than another that take 4 times more for the same amount of users.”

Here are few tips to carry out procedure along with an example:

Apache Benchmark Procedures

  • You need to use same hardware configuration and kernel (OS) for all tests
  • You need to use same network configuration. For example, use 100Mbps port for all tests
  • First record server load using top or uptime command
  • Take at least 3-5 readings and use the best result
  • After each test reboot the server and carry out test on next configuration (web server)
  • Again record server load using top or uptime command
  • Carry on test using static html/php files and dynamic pages
  • It also important to carry out test using the Non-KeepAlive and KeepAlive (the Keep-Alive extension to provide long-lived HTTP sessions, which allow multiple requests to be sent over the same TCP connection) features
  • Also don’t forget to carry out test using fast-cgi and/or perl tests

Lire la suite…